我的程序正在从我的app.config中创建一个.exe.config,并且该exe会保留用户在我的程序运行期间和运行后对其所做的更改.
My program is creating a .exe.config from my app.config and that exe is retaining the changes the user makes to it throughout and after runs of my program.
太好了,除了我想在Windows窗体应用程序中添加一个按钮,允许用户将这些设置重置为在app.config中静态/手动更改的原始值.
That's great and all but I want to add a button to my windows forms app that allows users to reset those settings to the original values that are static/manually changed in my app.config.
做到这一点的最佳方法是什么?这就是我的app.config的全部内容.
What is the best way to do this? This is the entirety of my app.config.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="CacheDir" value="C:\blah\prod\cache" /> <add key="CheckFilesDir" value="C:\blah\prod\cache\cachefiles" /> <add key="GenerateTo" value="C:\Users\blah\Desktop" /> <add key="CustomVariable1Enabled" value="false" /> <add key="CustomVariable2Enabled" value="false" /> <add key="CustomVariable1" value="" /> <add key="CustomVariableValue1" value="" /> <add key="CustomVariable2" value="" /> <add key="CustomVariableValue2" value="" />
正常访问..
ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap(); configFileMap.ExeConfigFilename = "C:\\Users\\RJenkins\\Documents\\Visual Studio 2010\\Projects\\CacheConfigNinja\\CacheConfigNinja\\bin\\Debug\\CacheConfigNinja.exe.config"; //configFileMap.ExeConfigFilename = "C:\\Users\\RJenkins\\Documents\\Visual Studio 2010\\Projects\\CacheConfigNinja\\CacheConfigNinja\\bin\\Release\\CacheConfigNinja.exe.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);推荐答案
您可以调用 Reset() 方法.在文档中,此方法:
You can call the Reset() method on your Application Settings. From the documentation, this method:
将保留的应用程序设置值恢复为其相应的默认属性.
Restores the persisted application settings values to their corresponding default properties.
更多推荐
如何重新创建app.config.exe.config
发布评论