changing configuration file

  • Thread starter Thread starter EP
  • Start date Start date
E

EP

Is there a proper way through System.Configuration to change something in
the app.config file?

I'd like to change the port # in a file-based remoting configuration at
runtime.
 
Is there a proper way through System.Configuration to change something in
the app.config file?

No. It's by design. And it makes sense. In anything but a single
stand-alone PC scenario, your app would be in a directory which should
not be write-enabled for the average user. You're not supposed to
store user specific settings in the app.config file either.

That said, of course, you could just load the whole app.config file
into a XmlDocument (since it's a straightforward XML document), change
your setting(s), and write back the XmlDocument to disk.

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Marc said:
No. It's by design. And it makes sense. In anything but a single
stand-alone PC scenario, your app would be in a directory which should
not be write-enabled for the average user. You're not supposed to
store user specific settings in the app.config file either.

Although I understand your sentiments I don't fully agree. The nice thing
about configuration files is that many of the framework classes initialise
themselves from the config file, which is a great facility. However, as the
OP mentioned, if you want to provide different defaults for each possible
user then you cannot do this with the current mechanism. It seems odd that
you have machine defaults, per app defaults, but not per user defaults.

The good news is that they are fixing this in Whidbey.
That said, of course, you could just load the whole app.config file
into a XmlDocument (since it's a straightforward XML document), change
your setting(s), and write back the XmlDocument to disk.

IMO a better way to do this is to initialize the appropriate objects at
runtime (ie overriding the defaults that are read from the config file),
yes, I said above that the automatic configuration feature of many framework
classes is a nice thing, but until it is fixed its best to ignore it. If you
do this, you can then use isolated storage to store your own config files
(and by all means use XML if you wish) so that you get .NET to pick the
right file for the user.

Richard
 
Back
Top