tags:

views:

623

answers:

5

I feel like I am always reinventing the wheel for each application when it needs to load/save general settings to an xml file. What is the best way to manage basic application settings that the user can adjust and need to be saved/restored?

+2  A: 

Are you using Visual Studio? There's a built-in settings manager and I find it works well for most situations. Just don't forget to call Settings.Save() before the application quits.

lc
A: 

File / New Item... and choose Settings. You can then configure user and application settings and VS generates a class that gives you easy access to those settings.

HTH, Kent

Kent Boogaart
+4  A: 

I like the use of custom configuration sections in .config files coupled with loading external .config files instead of the standard app.config.

Tom Anderson
I agree, app.config / appsettings are bad practice IMO.
Chris Marisic
+2  A: 

Why do people recommend app.config or web.config? they are the ugliest files in the world. Try your own XML http://www.picnet.com.au/blogs/Guido/post/2009/09/10/XML-Settings-Files-No-more-webconfig.aspx

This design is easy to get used to and once you do you will never go back to those ugly files again.

gatapia
A: 

Probably not the "best" method (eg, bc it restarts the web app), but if you need something that's quick & dirty, like for a small app where you just need to access/change a handful of simple values, take a look at

http://www.dotnetspark.com/Forum/656-how-to-modify-webconfig-file-dynamically.aspx (see Lalit's response)

http://ramanisandeep.wordpress.com/2009/04/07/programming-the-webconfig-file-using-c/

Shaun3180