如何重新创建app.config.exe.config [英] how to recreate app.config.exe.config

查看:317
本文介绍了如何重新创建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);

推荐答案

您可以调用

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆