对webconfig文件中的connectingtring的修改,其它节点的修改都可以参考。
2007-08-08 09:15
501 查看
private void WriteConfigFile(string FilePath)
...{
if (!File.Exists(string.Format("{0}/{1}", m_strAssemblyPath, FilePath)))
...{
MessageBox.Show("Web配置文件丢失,请尝试重新安装解决该问题。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
XmlDocument document = new XmlDocument();
document.Load(string.Format("{0}/{1}", m_strAssemblyPath, FilePath));
XmlNode appSettingNode = document.SelectSingleNode("/configuration/connectionStrings");
XmlNode dbConnectionNode = document.SelectSingleNode("/configuration/connectionStrings/add[@name='" + ConnectionStringNodeName + "']");
if (dbConnectionNode != null)
...{
dbConnectionNode.Attributes["connectionString"].Value = GetConnectionString();
dbConnectionNode.Attributes["providerName"].Value = ProviderName;
}
else
...{
XmlElement elementAdd = document.CreateElement("add");
XmlAttribute keyAttribute = document.CreateAttribute("name");
keyAttribute.Value = ConnectionStringNodeName;
XmlAttribute valueAttribute = document.CreateAttribute("connectionString");
valueAttribute.Value = this.m_connection.ConnectionString;
XmlAttribute providerAttribute = document.CreateAttribute("providerName");
providerAttribute.Value = ProviderName;
elementAdd.Attributes.Append(keyAttribute);
elementAdd.Attributes.Append(valueAttribute);
elementAdd.Attributes.Append(providerAttribute);
appSettingNode.AppendChild(elementAdd);
}
document.Save(FilePath);
}
相关文章推荐
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 为什么VS2013里要在Web.config中加入以下节点,Json文件才可以载入?
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- iis7针对不同域名配置不同运行权限,所有共用web.config产生的问题均可以修改根配置文件解决
- 通过程序修改web.config/app.config文件中的节点(appSettings,connectionStrings,system.web/caching/outputCacheSettings)
- 在web.config和app.config文件中增加自定义配置节点
- 在asp.net中是用伪静态---修改webconfig配置文件
- 编程修改读写web.config文件
- 在线修改web.config文件的一些理解
- Web.config 中的 节点设置--灵活运用表单认证中的 deny 与 allow 及保护 .htm 等文件
- web.config 配置文件节点说明
- 对web.config文件的节点进行加解密
- (转载)在web.config和app.config文件中增加自定义配置节点
- 如何通过代码修改web.config文件
- 动态修改web.config文件
- 在web.config中配置实现可以上传大文件
- 在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等