Geeks With Blogs
Developers Friendly
This post will demonstrate about updating web.config file dynamically. Below is the code snippet.

string key = "iSourceID";
string value = "This is my New Value!";
string path = targetDirectory + "\\Web.config" ;

var config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = path }, ConfigurationUserLevel.None);

var element = config.AppSettings.Settings[key];
if (element == null)
{
config.AppSettings.Settings.Add(key, value);
}
else
{
        element.Value = value;
}
config.Save(ConfigurationSaveMode.Minimal, true);  
Posted on Tuesday, December 10, 2013 6:38 AM .NET | Back to top


Comments on this post: Updating Web.config Programmatically

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Manjunath K | Powered by: GeeksWithBlogs.net