我用下面这句读取配置
strServerName = System.Configuration.ConfigurationSettings.AppSettings["ServerName"];
假如我想通过程序修改配置,应该怎么改?

解决方案 »

  1.   

    http://singlepine.cnblogs.com/articles/293683.html
      

  2.   

    /// <summary>
    /// 修改config文件节点属性。
    /// </summary>
    /// <param name="Path">文件路径</param>
    /// <param name="Key">键</param>
    /// <param name="Value">值</param>
    public bool UpdateConfig(string Path,string Key,string Value)
    {
    try
    {
    XmlDocument doc = new XmlDocument();
    doc.Load(Path);
    XmlNode node = doc.SelectSingleNode(Key);
    XmlElement ele = (XmlElement)node;
    ele.SetAttribute("value",Value);
    doc.Save(Path);
    return true;
    }
    catch{return false;}
    }