Change App.Config value in RunTime

T.saravanan
Posted by T.saravanan under C# category on | Points: 40 | Views : 4910
Hi,
Namespace --> Using System.Configuration;

System.Configuration.Configuration appConfig=System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
appConfig.Appsettings.Settings.Remove(sConnectionKey);
appConfig.Appsettings.Settings.Add(sConnectionKey,sNewValue);
appConfig.Appsettings.SectionInformation.ForceSave=true;
ConfigurationManager.RefreshSection("Appsettings");
appConfig.Save(ConfigurationSaveMode.Full);
ConfigurationSettings.Appsettings[sConnectionKey]=sNewValue;

Here
sConnectionKey --> Key Name in Config File
sNewValue --> Its your New Connection Value

Thanks,
T.Saravanan :)

Comments or Responses

Login to post response