Store user settings into application folder

Posted on

Problem :

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 SettingsApplication Data<comp name>Keb.exe_Url_pbs4eg1o2ija22omldrwjxhdam0jxxi51.0.0.0user.config

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

Solution :

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *