本文介绍了如何重新创建app.config.exe.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序正在从我的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:

这篇关于如何重新创建app.config.exe.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:05