Read and Add a Key and Value into Application Configuration file using C#.net

Naraayanan
Posted by Naraayanan under C# category on | Points: 40 | Views : 2113
I am creating a Method for Read and Add a Key and Value into Application Configuration file using C#.net.So you call that method in your program(where you want)
Read and Display an Application Configuration file using C#.net
     public static void ShowConfigsetting()
{
foreach (string key in ConfigurationManager.AppSettings)
{
string value = ConfigurationManager.AppSettings[key];
string result = "Keys :" + " " + key + " " + "Key value:" + " " + value;
MessageBox.Show(result);
}
}


Add a Key and Value into Application Configuration file using C#.net
  public static void AddintoConfigsetting(string appkeys,string appvalues)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add(appkeys, appvalues);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSetting");
ShowConfigsetting();

}

Comments or Responses

Login to post response