Read and Write to configuration's files

Reading:
string value = ConfigurationManager.AppSettings["Setting1"];

Writing:
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["Setting1"].Value = "3";
config.AppSettings.Settings["Setting2"].Value = "blabla";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

When use configuration settings in your web.config you have tou use
WebConfigurationManager class.

1 comment:

  1. Hi, Nice stuff. I found a cool news widget for our blogs at www.widgetmate.com. Now I can show the latest news on my blog. Worked like a breeze.

    ReplyDelete