Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store user settings into application folder

I'm using setting from my C# application like this:

String str = Properties.Settings.Default.SETTINGS_NAME;

When I save this settings, a settings file is created on

C:\Documents and Settings\<user name>\Local Settings\Application Data\<comp name>\Keb.exe_Url_pbs4eg1o2ija22omldrwjxhdam0jxxi5\1.0.0.0\user.config

Is there a way to change this path to Application.ExecutablePath\user.config, and use it next time so my application can be more portable ?

like image 970
Milos Avatar asked Feb 04 '11 11:02

Milos


People also ask

Where are C# application settings stored?

settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects.

Where should app config be located?

The application configuration file usually lives in the same directory as your application. For web applications, it is named Web. config. For non-web applications, it starts life with the name of App.

How can you save the desired properties of Windows Forms application?

A simple way is to use a configuration data object, save it as an XML file with the name of the application in the local Folder and on startup read it back.


2 Answers

You can control the location of the user.config file by creating a custom SettingsProvider. Luckily for you, someone at CodeProject already did that.

See my answer here for all the details: How to make designer generated .Net application settings portable

like image 92
Ohad Schneider Avatar answered Oct 05 '22 23:10

Ohad Schneider


If you want it to be Single user or in other way make the configuration of your application portable i will use a custom config file like an .ini file and keep it my app's root folder.

That way any one want to have those settings can just copy it in his own app's root folder on some other computer. When app runs it just loads the settings and behave accordingly.

save data in a fixed format like

[setting_name] = [Setting_value]\n

or in XML file, with Tag name for setting and value for... well... value :)

You can also go with registry setttings but user don't feel it trivial to copy and merge .reg files

This is the way i have seen some PC Games (for eg. i frequently changed Crysis and MassEffect settings) and Softwares save their config files.

like image 33
Shekhar_Pro Avatar answered Oct 06 '22 01:10

Shekhar_Pro