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


Top 5 Contributors of the Month
david stephan

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();
myconf.Save();

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

Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com


     

Further Readings:

Responses

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