Results 1 to 2 of 2

Thread: read and write to the web.config file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128

    read and write to the web.config file

    hello all,

    i have a web application that i want users to be able to change the name of the server and database from a web page.

    i have got this to work using this...

    Code:
        Public Sub SetValue(ByVal key As String, ByVal value As Object)
            Dim ds As New DataSet()
            ds.ReadXml(System.Web.HttpRuntime.AppDomainAppPath & "web.config")
            Dim dr() As DataRow = ds.Tables("add").Select(String.Concat("key='", key, "'"))
            dr(0).Item("value") = value
            ds.WriteXml(System.Web.HttpRuntime.AppDomainAppPath & "web.config")
            ds.Clear()
        End Sub
    called by this:

    Code:
            Dim aw As New AppSettinsWriter()
            aw.SetValue("ConnectionPCSRead", "data source=" & txtServer.Text & ";initial catalog=" & lblDatabase.Text & ";persist security info=False;user id=sa;password=;packet size=4096")
    but i need to display the server and database apon load of the web page, so the user can see what they are editing!

    at the mo it's just empty text boxes.

    I need to display the "data source" in the server box,
    and to display the "initial catalog" in the database box.

    please could you help,

    thanks,

    Tom.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    There is an AppSettingsReader class in the System.Configuration namespace that can easily read the current values on Page_Load.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width