How do I save and retrieve application settings and fields in C#. In VB I use .ini files. Thanks.
Printable View
How do I save and retrieve application settings and fields in C#. In VB I use .ini files. Thanks.
There's a few ways you can do this. Of course you can continue to use .ini files if you wish. System.Configuration.ConfigurationSettings.AppSettings lets you retrieve settings stored in your app.config, but there's no mechanism to save back. Someone on this forum (sorry, can't remember who) wrote a class that allows saving as well. Maybe you can find with a search.
I've also used a class that holds all the properties I want, then serialize/deserialize to xml - easy to do, but a bit of a pain when you add new properties and need to read in an older version of the xml file.
Have also put stuff in an xml file and instead of serialization, just manually - like with XmlReader - read in.
Lately have been getting away from the app.config method for two reasons - you can't save settings, and my users like the have a different .ini/.config file for each user, rather than one for the application.