.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Serilization >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to serialize a list to file using XmlSerializer

Posted By:Jean Paul       Posted Date: November 02, 2010    Points: 15    Category: Serilization    URL: http://www.dotnetspark.com  

Serializing and Deserializing code

public void Serialize(string filename, List objectToSerialize)
    Stream stream = File.Open(filename, FileMode.Create);
    BinaryFormatter bFormatter = new BinaryFormatter();
    bFormatter.Serialize(stream, objectToSerialize);

public List Deserialize(string filename)
    List objectToSerialize;
    Stream stream = File.Open(filename, FileMode.Open);
    BinaryFormatter bFormatter = new BinaryFormatter();
    objectToSerialize = (List)bFormatter.Deserialize(stream);

    return objectToSerialize;
Please remember to add namespaces:
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend