Writing and Retrieving Configuration from an XML Document in C#

  • Thread starter Thread starter J-S
  • Start date Start date
J

J-S

Hi,



I'm a student and new to the .net framework. What is the best way to save
configuration properties (not user specific) for a C# application? I read a
few messages talking about using XML to save properties. I read about using
app.config, but it seems you have to manually edit the file in order to
change its values, and I don't want those values hard coded. I'm trying to
avoid the registry. In my reading I have concluded that using an XML file
would have more advantages over using the registry, .ini or .dat file.



In my application I have a few textboxes, and every time this application is
opened I would like it to remember what the last user wrote. How can I
implement this using XML? Are there any good and simple examples about
creating an XML document and then reading/writing to it in C#?



Thanks a lot,

J-S.
 
H

You can use XmlSerializer Class for this purpose. First you create a class, that set all the values of the textboxes into its properties. Then using the XmlSerializer Class serialize this class into a XML file. For accessing the values of the XML file Use XMLTextReader and XmlSerializer Class deserialze the file back into the class, use class properties to access the values

More more information see the MSDN topic Xml Serializatio

Regard

Soora
Microsoft India Community Sta
 
Back
Top