tags:

views:

1279

answers:

5

What is an easy way to save/load settings? I'd prefer it if each user has their own set of settings.

+16  A: 

If this is a desktop application, the best way to store application and/or user specific settings is to use the builtin methods. Using Settings in C#

Samuel
Yes, yes, yes! Please, for the love of all things holy, don't use the registry!
Jon B
+1 for the right answer+1 for Jon B comment
acidzombie24
+2  A: 

This would depend a lot on the type of application.

If this is a desktop application you could save information into the registry in the user's area. Or into their User directory on disk. If this is a web or server application, you would need to store it into a database keyed by user, or to a disk file named for each user or something.

Since you mention options, it seems like the client path is more likely.

Jason Coyne
+1  A: 

ConfigurationManager works pretty well (desktop application). In essence, you are using the app.config xml file to save settings. For most basic use, just edit the app.config. Add a key value pair for each setting you would like to save... then to access it, just do a ConfigurationManager.get..["yourKey"] and it will return the setting. Setting it is pretty much the same.

jle
+1  A: 

In .Net applications create settings like this with the built in settings options in Visual Studio - the values are saved in a config file, but VS gives you a nice interface to create them and a .Net class to access them in a strongly typed way. You can create user specific settings or app specific settings in this way.

To create a settings file double click on the Properties folder then select the Settings tab, then click the link to create a "settings.settings" file (yeah, great name!). Once you do this you'll see the actual settings stored in app.config and the autogenerated code to get to these is in Settings.designer.cs.

Steve Haigh
A: 

When you say, "each user has their own set of settings", are you talking about an app that is shared by colleagues via a network or an app on a shared computer?

Personally, I would go a the settings file route. You can use the registry, but that makes me leery. There have been places in Windows (assuming you're on Windows) to store User Data for forever and a day, all you need to do is write to them. And if you're on Vista, writing to the registry may not be an option, unless you want to UAC prompt your users.

If your app already uses a SQL back end of some kind, use that. Make a settings table, or a key/value bag and store it there. Serialize that into an object and vice verse and you should have a version 1 of a settings manager.

Check out the ConfigurationManager and SpecialFolders, that should get you started.

Chris