Home > Code > C# > Dynamically change the web.config file key value using C#.net

Dynamically change the web.config file key value using C#.net

by Narain_Siddharth   on Dec 14, 2011   Category: C#   |  Views: 155    |  Points: 25   |  Silver 




The below sample C# code shows how to change the key value of appsettings in the web.config file dynamically.


web.config file settings
<appSettings>
<add key="Time" value="10" />
</appSettings>

Namespace details
using System.Web.Configuration;
using System.Configuration;

code
Configuration AppConfigSettings = WebConfigurationManager.OpenWebConfiguration("~");
AppConfigSettings.AppSettings.Settings["Time"].Value = "10";
AppConfigSettings.Save();





Like this code? Bookmark and Share:

  User Responses | Post Code
 No Response found!
  Recent Posts
* Setting focus to textbox control using JavaScript (308) by Narain_Siddharth on Nov 13 2010 11:25AM
* Sending Mails with Attachements using Asp.Net (362) by Narain_Siddharth on Nov 13 2010 11:48AM
* Disable the Submit button when insert or update a record using JavaScript (278) by Narain_Siddharth on Nov 13 2010 12:31PM
* String comparisons using C#.NET string.compareTo (289) by Thamilselvanj on Nov 14 2010 11:16AM
* String.Split using C# (287) by Thamilselvanj on Nov 14 2010 11:23AM
  Submit feedback about this code snippet
Please sign in to post feedback