I have a appsetting section in appconfig file as
<appSettings>
<add key="DayTime" value="08-20"/>
<add key="NightTime" value="20-08"/>
</appSettings>
I am tyring to modify the app config while application is running. I changed key DayTime to 11-20 while application is running.
Now if I run this code again to fetch data from config, it shows previous set values.
private void btnDayNightSettings_ShowingEditor(object sender, ItemCancelEventArgs e)
{
string[] strDayTime = ConfigurationManager.AppSettings["DayTime"].Split('-');
}
Why it is so ?
The reason behind why the AppSetting section in app.config file is not getting reflected during update in Run time is as follows:
.Exe files in Debug/Release folder; depending upon the Build mode..config file which looks like YourApplicationName.exe.config which holds the same entries in original app.config file. And the .Exe always refers to this file.app.config at Runtime it actually updates the file but changes are not updated in YourApplicationName.exe.config file as it has not re-build yet.So every time you need to re-build to your app to reflect the changes.
I have my own answer. Just need to refresh appSettings section as
ConfigurationManager.RefreshSection("appSettings");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With