The following lines of code changes the appSetting section "DEFAULT_LANGUAGE" and
refreshes the current page (causes re-load of the entire web as we modify the Web.config)
using System.Web.Configuration;
using System.Configuration;
private AppSettingsSection section;
protected void btnSave_Click(object sender, EventArgs e)
{
Configuration config= WebConfigurationManager.OpenWebConfiguration("~");
section = (AppSettingsSection)config.GetSection("appSettings");
section.Settings["DEFAULT_LANGUAGE"].Value ="some language";
config.Save();
Response.Redirect(Request.Url.ToString());
}
For windows applications code is listed below.
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["oldPlace"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Happy Coding...!
samitha
No comments:
Post a Comment