您的位置:首页 > 编程语言

用代码修改Web.Config里的键值

2008-05-22 08:26 295 查看
原则与操作XML文件相同。

Private Sub SaveSetting(ByVal strKeyName As String, ByVal strKeyValue As String, ByVal strWhich As String)

'创建XML文档实例
Dim XMLWebSetting As System.Xml.XmlDocument = New System.Xml.XmlDocument
'打开XML文档
XMLWebSetting.Load(System.Web.HttpContext.Current.Server.MapPath("~/" + strWhich + ""))

'查找节点所在位置
Dim XmlNodeList As System.Xml.XmlNodeList = XMLWebSetting.SelectSingleNode("//appSettings").ChildNodes
Dim xn As System.Xml.XmlNode
Dim xe As System.Xml.XmlElement
Try
For Each xn In XmlNodeList
xe = CType(xn, System.Xml.XmlElement)
If xe.Attributes("key").InnerText = strKeyName Then
xe.Attributes("value").InnerText = strKeyValue
XMLWebSetting.Save(System.Web.HttpContext.Current.Server.MapPath("~/" + strWhich + ""))
Exit For
End If
Next
Catch
End Try
End Sub

过程使用:SaveSetting("ConStr", Trim(TextBox1.Text), "web.config")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: