title: files and binary formatter
body: <p>I want to ask how to create and write a text file using binary formatter I have written the below code but I have an exception.
  the exception is :
  file can not been access because it is has been used by another process.</p>
  
  <p>and my code  creates two files one is with extension ".txt" and the other without any extension.</p>
  
  <p>what should I do? 
  Is there another way to create a text  file ?</p>
  
  <pre><code>using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.IO;
  using System.Runtime.Serialization.Formatters.Binary;
  using System.Runtime.Serialization;
  
  
  namespace ConsoleApplication9
  {
      [Serializable]
      class contact
      {
  
  
  
          string name;
          string address;
          string phonenumber;
          string emailaddress;
          public override string ToString()
          {
              return name + "   " + address + "   " + phonenumber + "  " + emailaddress;
          }
  
          public void AddContent(string cname, string caddress, string cphone, string cemail)
          {
              name = cname;
              address = caddress;
              phonenumber = cphone;
              emailaddress = cemail;
  
              FileStream file = new FileStream("contact.txt", FileMode.OpenOrCreate, FileAccess.Write);
  
              BinaryFormatter bin = new BinaryFormatter();
              contact person = new contact();
              person.name = cname;
              person.address = caddress;
              person.phonenumber = cphone;
              person.emailaddress = cemail;
              bin.Serialize(file, person);
              file.Close();
  
              Console.WriteLine(" added sucefully");
  
  
          }//end of fun add
  </code></pre>
  
  <p>}</p>