访问特殊文件夹中的App.exe.config文件 [英] Accessing App.exe.config File in Special Folders
问题描述
全部,我通常在使用
Properties.Settings.Default.SomeSetting = someVal;
Properties.Settings.Default.Save();
我被要求在安装之间保持设置,并且有两条路线;切换到使用注册表,或将.config文件保存到在两次安装之间保留的单独的特殊文件夹(由于设置数量,我选择了后者)。
I have been asked to persist settings between installations and there are two routes; switch to using the registry, or save the .config file to a separate Special Folder that is persisted between installations (I have chosen the later due to number of settings).
我的.config文件被写入一个奇数目录,即
My .config gets written to an odd directory, namely
C:\Users\Administrator\AppData\Local\MyApp\
MyApp.vshost.exe_Url_mzfwtdo5po4pcuabybebhsn5yfltbb3w\1.0.0.0
我的问题是:如何在C#中选择此目录?
注意:我已经尝试过
string appPath = Application.ExecutablePath;
Configuration config = ConfigurationManager.OpenExeConfiguration(appPath);
string strIPACostConfigFile = config.FilePath;
这是在安装目录中给我的初始.config文件。
Which gives me the initial .config in the installation directory.
谢谢您的时间。
推荐答案
您不必知道配置文件的位置。您只需要默认为 true
的设置,并在程序启动时调用以下调用即可。
You don't have to know the location of your config file. You just need a Setting that is true
by default and call the following call when your programm starts.
if (Settings.Default.IsUpgrade)
{
Settings.Default.Upgrade();
Settings.Default.IsUpgrade = false;
Settings.Default.Save();
}
这样,早期版本中的设置将被迁移到新版本中
That way, settings made in an earlier version will be migrated to the new one.
这篇关于访问特殊文件夹中的App.exe.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!