C#修改配置文件

View Code
bool isModified = false;

           foreach (string key in ConfigurationManager.AppSettings)
           {

               if (key == "box")
               {



                   isModified = true;

      }

           }


           Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);


           if (isModified)

           {

               config.AppSettings.Settings.Remove("box");

           }
           config.AppSettings.Settings.Add("box", txt_value.Text);

           config.Save(ConfigurationSaveMode.Modified);

           ConfigurationManager.RefreshSection("appSettings");

 

posted @ 2012-05-24 17:30  石 磊  阅读(379)  评论(0编辑  收藏  举报