对webconfig文件中的connectingtring的修改,其它节点的修改都可以参考。

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

你可能感兴趣的:(对webconfig文件中的connectingtring的修改,其它节点的修改都可以参考。)