Can you write to the .config file?

F

feng

..Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?

Thanks.

feng
 
R

Rob Windsor [MVP]

No. The app settings in the config file are meant to be read-only. As you
mentioned you can edit the config file using XML classes but if you want
read/write settings you should do it outside of the config file.
 
W

William Ryan eMVP

Feng:

Like Rob mentions, you can't write to it explicitly, however, I think I
heard a rumor that that's going to change in Whidbey (but I'm not positive).

Anyway, it's very easy to dupblicate though(although if you roll your own
you won't have the inherent designer support for dynamic properties). A
coworker of mine wrote this example
http://www.knowdotnet.com/articles/csettings.html that you may find helpful

HTH,

Bill
 
H

Herfried K. Wagner [MVP]

* "feng said:
.Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?

Config files are not the right place to store "user preferences", so you
cannot write them.

Configuration Management Application Block
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/cmab.asp>

<http://www.palmbytes.de/content/dotnetlibs/optionslib.htm>
 
S

Sueffel

feng said:
.Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?

Thanks.

feng

It isn't the best recommended practice to write to the App.config file, but,
check tomorrow morning on my website http://www.tiberiansun.us/projects and
I will post my DLL up there that does exactly that. My suggestion, write
code to make your own XML file that replaces the traditional INI file. I
have attempted to start one, but just haven't had the time to finish it.
Some say "Use the registry", but I don't like that, I like using the XCopy
Install feature of .NET, just copy the files and run. Anyhew, check about
10am EST for the DLL there.

Sueffel
 

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