rcj
rcj

Reputation: 661

how to recreate app.config.exe.config

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.

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.

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="" />

Normally access like..

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);

Upvotes: 2

Views: 1795

Answers (2)

Chamika Sandamal
Chamika Sandamal

Reputation: 24292

How about this?

Properties.Settings.Default.Reset()
Properties.Settings.Default.Reload()

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564333

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.

Upvotes: 2

Related Questions