如何重新创建app.config.exe.config

编程入门 行业动态 更新时间:2024-10-25 15:35:07
本文介绍了如何重新创建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:

将保留的应用程序设置值恢复为其相应的默认属性.

Restores the persisted application settings values to their corresponding default properties.

更多推荐

如何重新创建app.config.exe.config

本文发布于:2023-11-04 01:12:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556549.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:app   config   exe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!