SoapFormatter in C#

Its stored in this path:
["Your Drive"] : \ Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\ [".Net version"] \Profile\Client\
SOAPFormatter implements IFormatter interface which has 2 functions named Serialize and Deserialize to do the job for you.
Serializer takes two arguments: Stream and Object.
Stream argument depends on the file to be serialized to and Object argument tells us which object is going to be can be any type of list since it's an object. But we preferred using a List of string values.
Note that, SoapFormatter doesn't accept Generics Lists such as List<T>.
Alright let's create a new project in Visual Studio and see how it works:
Add Reference to the "System.Runtime.Serialization.Formatters.Soap" which is stored in the path i gave above.
Then add these namespaces to your project:
  1. using System.IO;  
  2. using System.Collections;  
  3. using System.Runtime.Serialization.Formatters.Soap; 
After that create 2 functions for the serialization and deserialization to the file.
  1.  private static void Serializer(ArrayList list)  
  2. {  
  3. }  
  4. private static ArrayList Deserializer()  
  5. {  

Now create a file named "users.soap" to store the object to be serialized to and Serialize it!
  1. private static void Serializer(ArrayList list)  
  2. {  
  3.   using (FileStream fs = File.Create("users.soap"))  
  4.   {  
  5.      SoapFormatter sof = new SoapFormatter();  
  6.      sof.Serialize(fs, list);  
  7.   }  
  8. }  
Then for the Deserialization, you've to open this file in OpenRead mode for deserializing and rebuilding the file that's serialized.
  1. private static void Serializer(ArrayList list)  
  2. {  
  3.   using (FileStream fs = File.Create("users.soap"))  
  4.   {  
  5.     SoapFormatter sof = new SoapFormatter();  
  6.     sof.Serialize(fs, list);  
  7.   }  
  8. }  
Now, let's add some values to our ArrayList object, serialize and deserialize it to rebuild the users.soap file.
  1. ArrayList users = new ArrayList();  
  2. users.Add("Ibrahim Ersoy");  
  3. users.Add("Gandalf");  
  4. users.Add("Sauron");  
  5. users.Add("Mouth Of Sauron - The Funny Guy");  
  6. Serializer(users);  
  7. ArrayList userlist = Deserializer(); 
To get the results we can use a foreach to iterate the requested kind of information according to the data types.
  1. foreach (string s in userlist)  
  3.   textBox1.Text += s + Environment.NewLine;  
After you run and test it, you'll see to it that your file has been created and ready to work.