本处主要是指读取和修改appSettings节点:

读取:

 string port = ConfigurationManager.AppSettings["port"];  //port字符不区分大小写,但注意config文件中port前后不要有空格,否则出错

写入:

 Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings["port"].Value = (int.Parse(port) + 1).ToString();
            configuration.Save();
            ConfigurationManager.RefreshSection("appSettings");  //此行刷新非常重要,否则再次读到时还是旧值,并且可能也未保存到磁盘中

相关文章:

  • 2021-12-28
  • 2021-06-17
  • 2021-09-07
  • 2021-10-13
  • 2022-12-23
  • 2021-10-03
猜你喜欢
  • 2022-01-12
  • 2022-12-23
  • 2021-07-19
  • 2021-08-06
相关资源
相似解决方案