Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Savu\ing the properties of a class?? 1

Status
Not open for further replies.

Norviking

Programmer
Nov 2, 2002
33
NO
I made a new class with lots of data. I now want to save this class data to a file. How should I "attack" this problem?? Do I have to write each and every property data of the class to a file, or can I save the hole class in go??

What is the best way to save a file, for security reasons?? I dont want a text file.

Plz help...
 
What you are trying to do is called serialization and you can find it very easily in MSDN online.
Basically, you mark your class with the [Serializable] attribute and then use something like this:

MyObject obj = new MyObject();
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, obj);
stream.Close();

There are some other formatters available, including an XML one.

If you want a safer way, you can use crypted streams to write data. .NET framework supports different encrypting methods, both symmetric and asymmetric, like RSA for example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top