Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

like image 920
LeoD Avatar asked Aug 25 '08 16:08

LeoD


People also ask

Where are .NET user settings stored?

The settings are stored in user. config. Full path: %USERPROFILE%\Local Settings\Application Data\<Company Name>\ <appdomainname>_<eid>_<hash>\<verison>\user.

Where are user settings saved C#?

User settings are saved in a file within a subfolder of the user's local hidden application data folder.

Where are application settings stored?

User-scope settings are stored in the user's appdata folder. Application-scope settings are stored in C:\Users\My Name\AppData\Local\My_Company\. If your settings file doesn't contain any Application-scope settings, you won't have a company folder.

How do I save settings in Visual Studio?

For your requirement, I suggest you export installation configuration files to save the workload and component information: open your VS installer > More > Export configuration. Meanwhile, you can export your environment settings by launching your VS > Tools > Import and Export settings.


1 Answers

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.

like image 127
Ryan Farley Avatar answered Oct 22 '22 21:10

Ryan Farley