writing in app.config

  • Thread starter Thread starter sam
  • Start date Start date
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
 
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.
 
Back
Top