.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Modify the value of key in appsetting section of web.config at runtime

Posted By:Lakhan Pal Garg       Posted Date: November 02, 2009    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  

Modify the value of key in appsetting section of web.config at runtime.

This code snippets will describe the way with which we can change the value of key present in the appsetting section of the web.config.

Suppose you have a key named Price as:

and you want to change this value dynamically.

Code to Change the above Value:

Namespace needs to added for this:

using System.Configuration;
using System.Web.Configuration;

Configuration myconf = WebConfigurationManager.OpenWebConfiguration("~");
myconf.AppSettings.Settings["Price"].Value = txtPrice.Text.Trim();

In the above code txtPrice.Text contains the new value for price.

Thanks & Regards
Lakhan Pal Garg


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend