C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






XML Serialization and DeSerialization C#


Posted Date: 03 Jun 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: shakti singh tanwarMember Level: Diamond    
Rating: Points: 8



For XML Serialization the class must have Serializable attribute and a default constructor


public void XMLSerialization(MyClass obj, String filename)
{
XmlSerializer serializer = null;
FileStream stream = null;
try
{
serializer = new XmlSerializer(typeof(MyClass ));//Must specify type for XMLSerializer
stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
serializer.Serialize(stream, obj);
}
finally
{
if (stream != null)
stream.Close();
}
}

The following code listing shows how we can implement XML de-serialization.


public static MyClass XMLDeserialization(String filename)
{
XmlSerializer serializer = null;
FileStream stream = null;
MyClass obj= new MyClass ();
try
{
serializer = new XmlSerializer(typeof(MyClass));
stream = new FileStream(filename, FileMode.Open);
obj= (MyClass)serializer.Deserialize(stream);
}
finally
{
if (stream != null)
stream.Close();
}
return obj;
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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: day check
Previous Resource: How to Encode string to Base64 format
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use