c# - How to dynamically apply changes to app.config on program start? -
My program uses some environmental data, which is referenced in the 'app.config' file:
< Pre> & lt; Configuration & gt; ... & lt; EnvUnderTest path = "settings_a.xml" /> ... & lt; Configuration & gt;
It is necessary to switch from time to time between this data, but I do not like an idea to change the 'app.config' file directly. Therefore, I thought it was better If the program starts, the 'path' parameter will change.
Can you tell me how it can be done?
I have tried the following code:
string te = Configuration Manager. App Settings ["EnvUnderTest"]; Configuration cfg = Configuration Manager OpenXE configuration (Configuration subcl. NO);
but te is the variable value tap , so I do not know how I can use this parameter value at runtime .
You are not using a properly configured file: try it
& lt; Configuration & gt; ... & lt; App settings & gt; & Lt; Add key = "EnvUnderTest" value = "settings_a.xml" /> & Lt; / AppSettings & gt; ... & lt; / Configuration & gt;
This should work with the code provided by you. Obviously, any other key you want to add is also & lt; App settings & gt;
.
Comments
Post a Comment