How to serialize a Hashtable

  • Thread starter Thread starter Diego F.
  • Start date Start date
D

Diego F.

I need to serialize a hash table in a file (xml or other), but I'm new with
all this and I don't know how to serialize. Can you put me a piece of code
to do this?

Regards,

Diego F.
 
Diego said:
I need to serialize a hash table in a file (xml or other), but I'm
new with all this and I don't know how to serialize. Can you put me a
piece of code to do this?

Regards,

Diego F.

Hi Diego,

A real easy way to do this is using a Soap Formatter (in
System.Runtime.Serialization.Formatters.Soap)

Create a stream (filestream or whatever) and use the serialize method
of the SoapFormatter.

i.e.

HashTable ht = new HashTable();
<snip - Code that populates the HashTable>

SoapFormatter sf = new SoapFormatter();
FileStream fs = new FileStream(TheFileName,FileMode.Create);
sf.Serialize(fs,ht);

(There is a Deserialize method as well to get it back.)

Rgds Tim.
 
A Hashtable is serializable, that means, you can use a formatter to
serialize it...

Lookup:

Binary.BinaryFormatter class. It has a serialize method that will help you.

-vJ
 
Back
Top