Visual Basic .NET Binary File Writing
I am used to C++ and being to write out an object bit for bit to a file by getting the size of the object in bytes, getting a pointer to the object and then writing each dword to the file and incrementing the pointer. Now I have to use Visual Basic to do this same task. Does anyone know how I can write out a bit for bit copy of an object (in this case a DataTable or DataSet) to a binary file? I have tried marshalling but the Marshal doesn''t take to kindly to DataSets =] (probably something I am doing)
Any Ideas?
For DataSets, you can use the WriteXml method which serializes the whole thing to XML. You should also be able to serialize it like any other .NET object, somewhat like this(C# syntax):
PS: Serialization in .NET is a lot more intelligent than the way you are used to doing it in C++, since it will serialize the entire object graph(all objects referenced by the object you are serializing).
"If there is a God, he is a malign thug."
-- Mark Twain
IFormatter formatter = new BinaryFormatter();Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);formatter.Serialize(stream, myDataSet);stream.Close();
PS: Serialization in .NET is a lot more intelligent than the way you are used to doing it in C++, since it will serialize the entire object graph(all objects referenced by the object you are serializing).
"If there is a God, he is a malign thug."
-- Mark Twain
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement