Editing a config file on the fly

I need a way to edit a config file on the fly. Does anyone have any insight on this

Answer this question

Editing a config file on the fly

  • Rockbooster

    As Ken mentioned, it's right here:  <a href="http://www.windowsforms.net/Forums/ShowPost.aspx tabIndex=1&tabId=41&PostID=828">INI files</a>

    It's really easy to make your own using an XPath query if you still want to after reading that thread.

    Actually, I realized I can't find my code that I've used for this!  :(  If the following code doesn't work it should at least be close.  I think my XPath query might be a little funky.


    Public Sub UpdateAppSettings(ByVal Key As String, ByVal Value As String)

         Dim Config As New System.Xml.XmlDocument()

         Config.Load("App.config")

         'make any changes here
         'this one just changes one item
         Config.SelectSingleNode("/configuration/appSettings/add[attribute::" & Key & "]").Attributes.GetNamedItem("value").Value = Value

    End Sub


    If you're worried about performance, like if you need to use it for ASP.NET or something, you could probably write a more efficient one, but for WindowsForms where you only have one person executing the code at a time, this should work just fine.

  • John_123456789

    Thanks! All try this and see if I can get this to work the way I need it too! Thanks!
  • Tech_Prince

    Funny, just discussed this. See the thread titled "ini files" in this forum for some ideas. -- Ken
  • Editing a config file on the fly