Recent Posts

Tags

Community

Email Notifications

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)

Archives

Add AppSettings Keys Programatically

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

 

Leave a Comment

(required) 

(required) 

(optional)

(required)