Adding values to a configuration block.

  • Thread starter Thread starter UJ
  • Start date Start date
U

UJ

How do you add a new value to a configuration file through the configuration
block through code? When I try and add a new value I get an exception.

TIA - Jeff.
 
Jeff,

When you say add new values ot a configuration file, i assume you mean the
application configuration files. Please see example below.

<Configuration>
<appSettings>
<add key="NewKey" value="MyNewValue" />
</appSettings>
</Configuration>

And to read the configurations back you can do something like
string MyValue =
System.Configuration.ConfigurationSettings.AppSettings["NewKey"];

Regards
Scott Blood
C# Developer
 
No I mean through the Configuration Application Block. When I attempt to add
an item that isn't there I get an exception.

scott blood said:
Jeff,

When you say add new values ot a configuration file, i assume you mean the
application configuration files. Please see example below.

<Configuration>
<appSettings>
<add key="NewKey" value="MyNewValue" />
</appSettings>
</Configuration>

And to read the configurations back you can do something like
string MyValue =
System.Configuration.ConfigurationSettings.AppSettings["NewKey"];

Regards
Scott Blood
C# Developer

UJ said:
How do you add a new value to a configuration file through the
configuration block through code? When I try and add a new value I get an
exception.

TIA - Jeff.
 

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

Back
Top