Wednesday, December 17, 2008

Example for XMLSerializer

This Program is used to create diferent type of values like textbox,lablebox,datagrid into xml file format

//Serialization

TextBox1.Text = "VIJAY WELCOMES U";
XmlSerializer xmlserial = new XmlSerializer(TextBox1.Text.GetType ());
FileStream fs = File.Create("C:\\vijay.xml");
xmlserial.Serialize(fs, TextBox1.Text);
fs.Close();

//Deserialization

object a;
XmlSerializer xmlserial1 = new XmlSerializer(TextBox1.Text.GetType());
FileStream fs1 = File.OpenRead("C:\\vijay.xml");
a=xmlserial1.Deserialize(fs1);
TextBox2.Text = (Convert.ToString(a));
fs1.Close();

Output ill be:

In xml file:
Below line ill show in xml format tag with in tag name "string"
VIJAY WELCOMES U

In form:
VIJAY WELCOMES U-- TextBox1
VIJAY WELCOMES U-- TextBox2

No comments: