Def:- Serialization is the conversion of an object into a transformable Form (XML or Binary). Deserialization refers to the converstion of data from XML or Binary format to Object.
Step:1 a) Create a class ClsEmp and define property like this
public class ClsEmp { string empNam; public ClsEmp() { // // TODO: Add constructor logic here // } #region Property public string _empNam { get { return empNam; } set { empNam = value; } } #endregion }
Step:2 a) Place two button on the deafult page named btnSerial and btnDeserial.On_Click events :
using System.Xml.Serialization; using System.IO;
protected void btnSerial_Click(object sender, EventArgs e) { objEmp._empNam = "ITM Business Solution"; XmlSerializer srX = new XmlSerializer(typeof(ClsEmp)); FileStream fs = new FileStream(Server.MapPath("sample.xml"), FileMode.Create, FileAccess.Write); srX.Serialize(fs, objEmp); fs.Close(); }
protected void btndeserial_Click(object sender, EventArgs e) { XmlSerializer srDX = new XmlSerializer(typeof(ClsEmp)); FileStream fs = new FileStream(Server.MapPath("sample.xml"), FileMode.Open, FileAccess.Read); objEmp = (ClsEmp)(srDX.Deserialize(fs)); Response.Write(objEmp._empNam); fs.Close(); }
step:3
a)Run this code and see the accurate result. b)we can also check the serialized file 'sample.xml' parsed in XML format.
|
| Author: Sumit 27 Dec 2008 | Member Level: Silver Points : 1 |
Good One.......
Keep it up........
it really helps the developers
regards Sumit
|