App.Config - Read and Save

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Costanzo

    #1

    App.Config - Read and Save

    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.Configur ation 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


  • Chris Dunaway

    #2
    Re: App.Config - Read and Save

    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.

    Comment

    • Eric Moreau

      #3
      Re: App.Config - Read and Save

      see


      --


      HTH

      Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
      (http://aspnet2.com/mvp.ashx?EricMoreau)
      Conseiller Principal / Senior Consultant
      Concept S2i inc. (www.s2i.com)

      "Stephen Costanzo" <sxcostanzo@hot mail.com> wrote in message
      news:OjZydrrlFH A.2904@tk2msftn gp13.phx.gbl...[color=blue]
      > 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.Configur ation 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
      >
      >[/color]


      Comment

      • Tibby

        #4
        Re: App.Config - Read and Save

        Stephen Costanzo wrote:
        [color=blue]
        > 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.Configur ation 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[/color]

        E-mail me (tierscheiss197 7 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

        Comment

        • Chad Z. Hower aka Kudzu

          #5
          Re: App.Config - Read and Save

          "Chris Dunaway" <dunawayc@gmail .com> wrote in news:1122917801 .219032.193180
          @o13g2000cwo.go oglegroups.com:[color=blue]
          > In response to your question, you could use the System.Xml namespace to
          > read and write values to the app.config file.[/color]

          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:



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

          Make your ASP.NET applications run faster

          Comment

          • Chad Z. Hower aka Kudzu

            #6
            Re: App.Config - Read and Save

            "Stephen Costanzo" <sxcostanzo@hot mail.com> wrote in
            news:OjZydrrlFH A.2904@tk2msftn gp13.phx.gbl:[color=blue]
            > Looking back in the group, I figured out how to read from the
            > appSettings section of the configuration file.[/color]

            appSettings is not designed to be read/write and you should not write to it.

            You might be interested in this:



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

            Get your ASP.NET in gear with IntraWeb!

            Comment

            Working...