writing in app.config

S

sam

Hi,

I use string sValue = ConfigurationManager.AppSettings["MyKey"] for reading
a value in my app.config, section AppSettings.
Ho to write in it for example to create a key and assign a value like this ?
ConfigurationManager.AppSettings["ANewKey"]="my value in app.config";

Thanks for help.

Sam
 
B

Barfy the Wonder Camel

Hi,

I use string sValue = ConfigurationManager.AppSettings["MyKey"] for reading
a value in my app.config, section AppSettings.
Ho to write in it for example to create a key and assign a value like this ?
ConfigurationManager.AppSettings["ANewKey"]="my value in app.config";

Thanks for help.

Sam

Short answer: Don't. app.config is in the same directory as your
executable, which means there's a good chance you won't have write
access in a properly secured environment (or on Vista in general, I
believe). Look up user.config for saving user-configurable settings.
user.config ends up in the Application Data subdirectory tree by
default.

The docs also hint that runtime write access to app.config is
explicitly denied, at least in VS2005.
 

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