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

## Recommended Posts

##### Share on other sites
Umm, why are you serializing to a MemoryStream instead of the file. That's an extra step.

##### Share on other sites
To be quite honest with you, I have no idea. I was given those directions, I followed them and after a bit of work, it worked :) it ain't really broken, and I'm more concerned about the Loading part really.

If you have a suggestion though, I'm all ears.

##### Share on other sites
If you fix both the load and save to go directly to the file it should work.

##### Share on other sites
Well, that's precisely the reason I'm posting here. Code-wise, I have no idea on how to do that.

As far as I can tell, I deserialized the contents of the file. Now, on how to get that back to the controls on my program, I fail miserably.

You understand my predicament, do you? I'm no expert at this.

##### Share on other sites
Part of the problem could be that you're going to and from a text file (via text-handling methods) when you're dealing with binary data.

I've never tried to serialise an entire form, nor used the binary serialisation stuff myself, but I suspect it should look something like this:

' Serialising "ObjectToSerialise" to file "SavedFile.bin"Using SaveStream As Stream = File.Create("SavedFile.bin")	Dim Formatter As New BinaryFormatter()	Formatter.Serialize(SaveStream, ObjectToSerialise)End Using' Deserialising "SavedFile.bin" back into "ObjectToDeserialise"Dim ObjectToDeserialiseUsing SaveStream As Stream = File.OpenRead("SavedFile.bin")	Dim Formatter As New BinaryFormatter()	ObjectToDeserialise = Formatter.Deserialize(SaveStream)End Using

Edit: Replaced File.OpenWrite with File.Create

[Edited by - benryves on February 29, 2008 7:54:36 PM]

##### Share on other sites
I guess I'll have to try that next time I check that part of the code. Thanks for the help.

##### Share on other sites
You could also use the XMLFormatter if you want the file to be readable/editable.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 32
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631409
• Total Posts
2999928
×