//de-serializing the object private void button2_Click(object sender, EventArgs e) { IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); Stream serialStream = new FileStream("f:\\SerializeFile.bin", FileModse.Open, FileAccess.Read, FileShare.Read); serializeObject srObj = (serializeObject)formatter.Deserialize(serialStream); serialStream.Close(); MessageBox.Show(srObj.srString + " " + srObj.srInt.ToString()); }
//serializing the object private void button1_Click(object sender, EventArgs e) { serializeObject srObj = new serializeObject(); srObj.srString = ".Net serialization test !!"; srObj.srInt = 1000; IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); Stream fileStream = new FileStream("f:\\SerializeFile.bin", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(fileStream, srObj); fileStream.Close(); MessageBox.Show("Object Serialized !!"); }