我想把<add key="iSystemConfig" value="DataAccess.SystemConfig"/>里面的value改变不知怎么改???下面是我的代码
Configuration configuration = ConfigurationManager.OpenExeConfiguration(@"C:\Documents and Settings\Administrator\桌面\MyDemo\WindowsApplication-Print\App.config");
            AppSettingsSection assSection = configuration.AppSettings;            assSection.Settings["iSystemConfig"].Value = "AAA";
            configuration.Save();路径没错的,或者其它办法也行

解决方案 »

  1.   

    ConfigurationManager打开配置不需要指定路径
    ---------------
    AppSettingsSection assSection = configuration.AppSettings;
    assSection.Settings["iSystemConfig"].Value = "AAA";
    configuration.Save(); 
    这么改是可以的, 但是save之后要强制刷新appsetting 有提供方法的,叫什么忘了
      

  2.   


                ExeConfigurationFileMap filemap = new ExeConfigurationFileMap();
                filemap.ExeConfigFilename = (@"C:\Documents and Settings\Administrator\桌面\MyDemo\WindowsApplication-Print\App.config";
                Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(filemap,ConfigurationUserLevel.None);
                AppSettingsSection assSection = configuration.AppSettings;
                assSection.Settings["iSystemConfig"].Value = "AAA";
                configuration.Save(); 
    如果要指定配置文件的话,我一般是用OpenMappedExeConfiguration,而不是用OpenExeConfiguration
    楼主可以试试
      

  3.   

     Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                configuration.AppSettings.Settings["iSystemConfig"].Value = "AAAA";
                configuration.Save();
    注意,起作用的是与你的.exe同名的.config文件。
      

  4.   

    把web.config当作xml来看待改就好了
             string _xmp = (@"C:\Documents and Settings\Administrator\桌面\MyDemo\WindowsApplication-Print\App.config");//web.config地址//当然要有权限
            XmlDocument _xmld = new XmlDocument();
            _xmld.Load(_xmp);
            XmlNode xn = _xmld.SelectSingleNode("configuration/appSettings/add[@key=‘iSystemConfig’]");
               if (xn != null)
                   xn.Attributes["value"].InnerText = “AAA”;
           _xmld.Save(_xmp);
      

  5.   

    /// <summary>
            /// 修改config文件节点
            /// </summary>
            /// <param name="key"></param>        
            public static bool ChangeToFile(string key, string value, string fileName)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(AppDomain.CurrentDomain.BaseDirectory + fileName);
                    XmlNode node = doc.SelectSingleNode(@"//add[@key='" + key + "']");
                    XmlElement ele = (XmlElement)node;
                    ele.SetAttribute("value", value);
                    doc.Save(AppDomain.CurrentDomain.BaseDirectory + fileName);
                    return true;
                }
                catch (Exception e)
                {
                    return false;
                }
            }