Creating a Web.config Editor - Part 2
page 4 of 4
by Jason N. Gaylord
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22470/ 27

Section 3: Implementing The Page
Then, we will use the same concept as Part 1 to save the node. This time we will use the a parameter to select which 'add' node we want to update.
EditConfig.aspx
**************************************************

1:   <%@ Page Language="vb" %>
2:   <%@ import Namespace="System" %>
3:   <%@ import Namespace="System.Xml" %>
4:   <script runat="server">
5:   
6:       Sub Page_Load(s as Object, e as EventArgs)
7:          Dim myConfig As New XmlDocument()
8:       
9:          myConfig.Load("C:\InetPub\wwwroot\web.config")
10:        
11:           If not isPostBack then
12:              Dim myCurrentValue as String
13:              Dim myListItem as ListItem
14:        
15:              myCurrentValue = myConfig.SelectSingleNode(
                  "configuration/appSettings/add[@key='conServer']
                  /@value").Value
16:              myListItem = node01.Items.FindByText(myCurrentValue)
17:        
18:              node01.SelectedIndex = node01.Items.IndexOf(myListItem)
19:           Else
20:             'We will save this for later!
21:           End If
22:        
23:        End Sub
24:        
25:        Sub Button_Click(s as Object, e as EventArgs)
26:           Dim myConfig As New XmlDocument()
27:           Dim myAttribute As XmlAttribute
28:        
29:           myConfig.Load("C:\InetPub\wwwroot\web.config")
30:           
31:           myAttribute = myConfig.SelectSingleNode(
                 "configuration/appSettings/add[@key='conServer']
                 /@value")
32:           myAttribute.Value = node01.SelectedItem.ToString()
33:           
34:           myConfig.Save("C:\InetPub\wwwroot\web.config")
35:        End Sub
36:    
37:    </script>
38:    <html>
39:    <head>
40:        <title>Web.config Editor</title>
41:    </head>
42:    <body>
43:        <form runat="server">
44:          <asp:Label id="title01" runat="server" text="Change Server:" />
45:          <asp:DropDownList id="node01" runat="server">
46:            <asp:ListItem Value="localhost" text="localhost" />
47:            <asp:ListItem Value="Server01" text="Server01" />
48:            <asp:ListItem Value="Server02" text="Server02" />
49:            <asp:ListItem Value="Server03" text="Server03" />
50:          </asp:DropDownList>
51:          <br />
52:          <asp:Button id="myButton" runat="server" Text="Update"
                 OnClick="Button_Click" />
53:        </form>
54:    </body>
55:    </html>

View Entire Article

User Comments

Title: Creating a Web.config Editor - Part 2   
Name: Kris Triyantio
Date: 2007-01-16 11:09:18 PM
Comment:
It's good, but i cannot save. it shown error message.
"access denied"
how can i handle that.

Thanks
Title: Creating a Web.config Editor - Part 2   
Name: Haroldo Carvalho
Date: 2006-02-01 9:58:14 AM
Comment:
Very good.
It realy helpped me.
Thanks

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2023 ASPAlliance.com  |  Page Processed at 2023-02-02 1:14:59 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search