Archived

This topic is now archived and is closed to further replies.

Visual Basic .NET Binary File Writing

This topic is 5380 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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):

  
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

Share this post


Link to post
Share on other sites