What is the best way to store user settings for a .NET application?

I have a .NET 2.0 Windows Forms application. Where is the best place the store user settings (considering Windows guidelines)?

Some people pointed to Application.LocalUserAppDataPath. However, that creates a folder structure like:

C:\Documents and Settings\user_name\Local Settings\Application Data\company_name\product_name\product_version\

If I release version 1 of my application and store an XML file there, then release version 2, that would change to a different folder, right? I'd prefer to have a single folder, per user, to store settings, regardless of the application version. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­


Solution 1:

I love using the built-in Application Settings. Then you have built in support for using the settings designer if you want at design-time, or at runtime to use:

// read setting
string setting1 = (string)Settings.Default["MySetting1"];
// save setting
Settings.Default["MySetting2"] = "My Setting Value";

// you can force a save with
Properties.Settings.Default.Save();

It does store the settings in a similar folder structure as you describe (with the version in the path). However, with a simple call to:

Properties.Settings.Default.Upgrade(); 

The app will pull all previous versions settings in to save in.

Solution 2:

.NET applications have a built-in settings mechanism that is easy to use. The problem with it, in my opinion, is that it stores those settings off into a rather obscure directory and end users will not be able to find it. Moreover, just switching from debug to release build changes the location of this directory, meaning that any settings saved in one configuration are lost in the other.

For these and other reasons, I came up with my own settings code for Windows Forms. It's not quite as slick as the one that comes with .NET, but it's more flexible, and I use it all the time.