Thursday, January 13, 2011

How to update Web.config dynamically?

I need to update web.config dynamically? So this is what I did, this code below has done the trick for me.

string value = "webmaster@company.com";
Configuration config = webConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appsetting = config.GetSection("appSettings");
appsetting.Settings("fromAddress").Value = value;
config.Save();
Make sure to add System.Web.Configuration in the namespace. Have fun Light bulb

No comments:

Post a Comment