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 ?
settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With