WPF FAQ - Serialization

How to write some XML into IsolatedStorage?
[C#]

Stream mystream = new IsolatedStorageFileStream( storeFileName, FileMode.Create, isoStorage );
if( null != mystream )
{
XmlTextWriter xmlwriter = new XmlTextWriter(mystream, Encoding.UTF8);
      this.WriteDateToWriter( xmlwriter );
      xmlwriter.Flush();
stream.Close();
}
Permalink
What is Serialization ?

Serialization is the process of converting the state of the object to a stream, so that it can be saved and transported. The reverse process of serialization is called Deserialization, where a stream is converted back to an object. The objective of serialization process is persistence of objects in an application. There are two types of Serialization: ’Binary and ’SOAP’ serialization respectively.

Permalink
How do I serialize objects to a binary file ?

Objects can be serialized to a binary file using the System.Runtime.Serialization and System.Runtime.Serialization.Formatters.Binary namespaces.

The following code snippet is used to write a stream to a binary file.

[C#]

SerializeTest st = new SerializeTest();
File file = new File('temp.dat');
Stream stream = file.Open(FileMode.Create);
BinaryFormatter binaryformatter = new BinaryFormatter();
binaryformatter.Serialize(stream, st);
stream.Close();
Permalink