This is by far not a nice approach to data storage. The problem is not the binary representation of data itself, but it's ad-hoc and non-flexible nature.
Anyway, you need to use the classes
System.IO.BinaryReader
and
System.IO.BinaryWriter
:
http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx[
^].
Basically, you would need to read and write the structure by component:
using System.IO;
BinaryReader reader = new BinaryReader();
eRecord myRecord =
myRecord.fName = reader.ReadString();
myRecord.lName = reader.ReadString();
myRecord.dep = reader.ReadString();
I don't know how you represented the date, so chances are, you would need to bread date into some primitive-type components like some integer types and read the one-by-one, using
reader.ReadUint32
,
reader.ReadUInt16
,
reader.ReadByte
or the like. You can check with some binary editor to see its binary structure or figure out from original code.
Writing is done in the same way with
BinaryWriter
, symmetrical to reading.
Next time, don't do such things. Learn serialization instead:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework[
^],
http://msdn.microsoft.com/en-us/library/ms233843.aspx[
^].
First of all, as a very easy-to-use, robust and universal approach to serialization, consider using
Data Contracts:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^].
Good luck,
—SA