I have an app.config like below,
<configuration>
<environment>
<add key="security" value="1"/> -- I want to change this value to 3
</environment>
</configuration>
I tried like below to get to environment section,
Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);
var environment = config.GetSection("environment");
environment variable doesn’t give me enough options to get the child elements to modify the value. Could any one please help me out in this one.
Use user scope settings!! NEVER EVER change the application configuration that way. Any value that is changed within the application should be a user setting.
Usually, you access these settings through
EDIT
Sample for doing what I wrote in the comments. Create two user settings:
FirstRunis aboolwhich is by default set totrue.Environmentis your value, by default set to0.Then, for example in the
Mainfunction inProgram.csyou’d do the following:Later in your application it is enough to use
Properties.Settings.Default.Environment. That’s how the settings mechanism is intended to be used if you want to change configuration values from your application.Under Windows 2000, XP, 7 and the Windows Server branch you would not even have the rights to modify the app.config in your Program Files folder, so don’t!