用代码修改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")
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")
相关文章推荐
- 用代码修改Web.Config里的键值
- 用代码修改Web.Config里的键值
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- ASP.NET程序中动态修改web.config中的设置项目(前台页面代码)
- ASP.NET中动态修改web.config中的设置项目(前台代码)
- asp.net代码中修改web.config节点的具体方法
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- ASP.NET中动态修改web.config中的设置项目(前台代码)
- ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)
- asp.net代码中修改web.config节点的具体方法
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- 动态添加修改WEB.CONFIG的具体代码方法
- 修改web.config中的键值
- ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)
- 如何通过代码修改web.config文件
- asp.net代码修改web.config
- web.config修改代码