您的位置:首页 > 其它

对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);


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐