System.Configuration.Configuration config =
       System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);            System.Configuration.ConfigurationManager.AppSettings.Set("IssueStation",this.textBox1.Text);            this.label2.Text = config.FilePath;
            config.Save();
           System.Configuration.ConfigurationManager.RefreshSection("appSettings");修改该配置文件后,调用config.Save();函数不能把修改后的文件保存到本地
调用System.Configuration.ConfigurationManager.RefreshSection("appSettings");
又会刷新成原来的文件,请问如何修改才能把配置文件保存到本地

解决方案 »

  1.   

    public void Modify(string key,string strValue) 

    string XPath="/configuration/appSettings/add[@key='?']"; 
    XmlDocument domWebConfig=new XmlDocument(); domWebConfig.Load( (HttpContext.Current.Server.MapPath("web.config")) ); 
    XmlNode addKey=domWebConfig.SelectSingleNode( (XPath.Replace("?",key)) ); 
    if(addKey == null) 

    throw new ArgumentException("没有找到<add key='"+key+"' value=.../>的配置节"); 

    addKey.Attributes["value"].InnerText=strValue; 
    domWebConfig.Save( (HttpContext.Current.Server.MapPath("web.config")) ); } 
      

  2.   

    除了用xml的方式有人知道 config.Save();为什么失败么?
      

  3.   

    #region 保存Web.config
    /// <summary>
    /// 保存Web.config
    /// </summary>
    /// <param name="strKeyName">节点名</param>
    /// <param name="strKeyValue">要保存的值</param>
    /// <param name="strWhich">哪个配置文件</param>
    public static void SaveSetting(string strKeyName, string strKeyValue,string strWhich) 

    System.Xml.XmlDocument XMLWebSetting = new System.Xml.XmlDocument(); 
    XMLWebSetting.Load(System.Web.HttpContext.Current.Server.MapPath("~/"+ strWhich +"")); 
    System.Xml.XmlNodeList XmlNodeList = XMLWebSetting.SelectSingleNode("//appSettings").ChildNodes; 
    try 

    foreach (System.Xml.XmlNode xn in XmlNodeList) 

    System.Xml.XmlElement xe = ((System.Xml.XmlElement)(xn)); 
    if (xe.Attributes["key"].InnerText == strKeyName) 

    xe.Attributes["value"].InnerText = strKeyValue; 
    XMLWebSetting.Save(System.Web.HttpContext.Current.Server.MapPath("~/"+ strWhich +"")); 



    catch (System.Exception Ex) 

    throw Ex; 

    }
    #endregion
      

  4.   

    .NET2.0么?
    我用Save方法一直用得好好的。