Store user settings into application folder

半城伤御伤魂 提交于 2019-12-30 04:33:09

问题


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 ?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4897525/store-user-settings-into-application-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!