MSMVPS.COM
The Ultimate Destination for Blogs by Current and Former Microsoft Most Valuable Professionals.
Add AppSettings Keys Programatically
Bilal Haidar [MVP]

Syndication

All Links

Blogs I Read

My Articles

JavaScript & CSS

Date & Time

SQL Server 2000/2005

Articles I Read

ASP.NET Free Controls

MVFP (Most Valuable Forum Posts)

In ASP.NET 2.0 Beta 2, two new configuration classes have been added:

1- ConfigurationManager:
     Used to update sections inside the App.Config file.

2- WebConfigurationManager:
    Used to update setions inside Web.Config file.

To see how to add some keys to the AppSettings section in the web.config file, check the code below:

Configuration configFile = 
WebConfigurationManager.OpenWebConfiguration("~"); AppSettingsSection AppSection =
configFile.GetSection("appSettings") as AppSettingsSection; AppSection.Settings.Add(
new KeyValueConfigurationElement("SMTP", "mail.bhaidar.net")
); configFile.Save();
The above code would add the following line to the appSettings section.
<appSettings>
<
add key="SMTP" value="mail.bhaidar.net" />
<
/appSettings>

Make sure to include:
using System.Web.Configuration;
Hope that helps you.
 
Regards

 


Posted Thu, Jun 23 2005 16:32 by simple

Add a Comment

(optional)  
(optional)
(required)  
Remember Me?


Copyright © is the original authors. Blog site is an independent site not sponsored by Microsoft. The Yoda blog server and the Brianna SQL server would like to thank www.ownwebnow.com and www.exchangedefender.com. They wouldn't be here and broadcasting without the generosity of Vlad Mazek and his companies.

Powered by Community Server (Commercial Edition), by Telligent Systems