1. Function to store has table
private void WriteHashTableInFile()
{
String strReportFileName=@"C:\test1.dat";
// Open file for write access. Must close file
FileStream objReportFileStream =
new FileStream (strReportFileName,FileMode.OpenOrCreate,FileAccess.Write,FileShare.Write);
BinaryWriter objBinWriter = new BinaryWriter(objReportFileStream);
objBinWriter.BaseStream.Seek(0, SeekOrigin.Begin);
byte[] buf = Serializer(mainHashTable);
objBinWriter.Write (buf);
objBinWriter.Flush();
objBinWriter.Close();
objReportFileStream.Close();
}
2. Write a function which serailize any object
private static byte[] Serializer(object obj)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms=new MemoryStream(); // Stream
bf.Serialize(ms,obj); // "Save" object state
ms.Seek(0,0);
byte[] data = new byte[ms.Length];
ms.Read (data, 0, data.Length);
ms.Flush ();
ms.Close ();
return data;
}