App.Config - Read and Save

  • Thread starter Thread starter Stephen Costanzo
  • Start date Start date
S

Stephen Costanzo

Looking back in the group, I figured out how to read from the appSettings
section of the configuration file.

I have default values for the application in the unlikely event that the
user deletes the configuration file. My question is this: How do I write the
defaults back out to the configuration file at run time? is this even
possible?

I understand that the System.Configuration API is read only so would I
basically have to read in the configuration file in total, create the XML
file (including the missing values) and write it back out using the normal
system.io ?

Thanks
 
You might look at the Enterprise Library and it's configuration
application block. It's very flexible and allows for reading and
writing.

In response to your question, you could use the System.Xml namespace to
read and write values to the app.config file.
 
Stephen said:
Looking back in the group, I figured out how to read from the
appSettings section of the configuration file.

I have default values for the application in the unlikely event that
the user deletes the configuration file. My question is this: How do
I write the defaults back out to the configuration file at run time?
is this even possible?

I understand that the System.Configuration API is read only so would I
basically have to read in the configuration file in total, create the
XML file (including the missing values) and write it back out using
the normal system.io ?

Thanks

E-mail me (tierscheiss1977 on Hotmail) and I'll send you a custom
library I made that allows Read/Write functionality to the appSettings
and userSettings section of the App.Config/Web.Config file. I use it
in all my projects that require me to use a .Config file.

maybe, when I get some time, I'll make an article on it on codeProject

Tibby
 
Chris Dunaway said:
In response to your question, you could use the System.Xml namespace to
read and write values to the app.config file.

Using System.XML is a good approach, but you should not write to app.config. Read the blogs on
MSDN and the comments in the footer of this article:
http://www.codeproject.com/dotnet/XMLSettingsFile.asp


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 

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

Similar Threads


Back
Top