Reading from App.config file:
using System.Configuration;
To read from app.config file you may use the following code:
private string ReadFromAppConfig(string key)
{
return ConfigurationManager.AppSettings[key];
}
To write to app.config file you may use the following code:
private void WriteToAppConfig(string key, string value)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
Sample App.Config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TimerInterval" value ="9000"/>
</appSettings>
</configuration>
using System.Configuration;
To read from app.config file you may use the following code:
private string ReadFromAppConfig(string key)
{
return ConfigurationManager.AppSettings[key];
}
To write to app.config file you may use the following code:
private void WriteToAppConfig(string key, string value)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
Sample App.Config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TimerInterval" value ="9000"/>
</appSettings>
</configuration>
View comments