Posts
33
Comments
147
Trackbacks
0
October 2010 Entries
XML Serialization - example

Serialization and De-serialization is very important concept in .Net world. I won't go in-depth of what each of them means.

In short, Serialization means converting your .Net object into some preservable format like xml string.

De-serialization is the exact opposite of this and it means converting your string into C# object.

In this article, I will show you a very simple working example of Serialization.

Suppose you want to Serializa an object obj of type obj_Type

Step 1:  Include System.Xml.Serialization namespace in your code

Step 2: Put the following lines of code

XmlSerializer xml = new XmlSerializer(typeof(obj_Type));

System.IO.TextWriter txt = new System.IO.StreamWriter(@"C:\test.xml");

xml.Serialize(txt, obj);

txt.close();

Following execution of this code, your object would be serialized into an xml file.

Hope this helps !!

Posted On Friday, October 1, 2010 10:19 AM | Comments (4)