C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Serialization »

Serialization&Deserialization


Posted Date: 27 Dec 2008    Resource Type: Code Snippets    Category: Serialization
Author: KusumMember Level: Bronze    
Rating: 1 out of 5Points: 10



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.




Responses

Author: Sumit    27 Dec 2008Member Level: Silver   Points : 1
Good One.......

Keep it up........


it really helps the developers

regards
Sumit


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Serialize the object in XML  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Deserialization of XML to Hashtable
Previous Resource: Object serialization
Return to Discussion Resource Index
Post New Resource
Category: Serialization


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use