Write AppSettings Keys Programmaticaly

S

Sylvie

I am Developing a web application and reading connection strings from
Web.Config file,

How can I write appSettings keys programmaticaly via a web page ?

Thanks

<?xml version="1.0"?>

<configuration>

<appSettings>

<add key="SQLServer" value="SERVER"/>

<add key="SQLDBName" value="DBNAME"/>

<add key="SQLUser" value="SA"/>

<add key="SQLPass" value="efgergfgds=="/>

</appSettings>
 
G

Guest

You should be posting this stuff in the ASP.NET newsgroup, it's not C# -
language specific.

public void Modify(string key, string value)
{
Configuration configuration =
WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettingsSection =
(AppSettingsSection)configuration.GetSection("appSettings");
if (appSettingsSection != null)
{
appSettingsSection.Settings[key].Value = value;
config.Save();
}
}

Don't forget when you do this, you have modified the web.config and your
application will recycle.

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top