The simplest way to serialize object, that is use class BinaryFormatter.
Sample of serialization to file:
using (FileStream stream = new FileStream(tempFilePath, FileMode.Create))
{
BinaryFormatter b = new BinaryFormatter();
b.Serialize(stream, originalData);
}
Sample of deserialization to file:
Data actualData;
using (FileStream stream = new FileStream(tempFilePath, FileMode.Open))
{
BinaryFormatter b = new BinaryFormatter();
actualData = (Data)b.Deserialize(stream);
}
where class Data has attribute [Serializable].
See sources on “C# tips samples” project.
Reference:
The simplest way to store object to .xml file in c#.
1 comment:
Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
www.imarksweb.org
Post a Comment