一。首先引用Configuration

1)App.config如下:

using System.Configuration;//若果还没有Configuration,右键引用文件夹添加引用,在.NET中找到System.configuration添加

2)Web.config如下:

using System.Configuration;

using System.Web.Configuration;

1)App.config页面代码如下:

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="name" value="张三"/>
</appSettings>
</configuration>

2)Web.config页面代码如下:

 <?xml version="1.0"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<appSettings>
<add key="name" value="张三"/>
</appSettings>
</configuration>

二。增加

1)App.config示例:

 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection appsettings = (AppSettingsSection)config.GetSection("appSettings");
appsettings.Settings.Add("color", "blue");
config.Save();
string str = ConfigurationManager.AppSettings["color"];

2)Web.config示例:

 Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Add("color", "blue");
config.Save(ConfigurationSaveMode.Modified);
string str=WebConfigurationManager.AppSettings["color"];

三。删除

App.config示例:

 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection appsettings = (AppSettingsSection)config.GetSection("appSettings");
appsettings.Settings.Remove("name");
config.Save();
ConfigurationManager.RefreshSection("name");
string str = ConfigurationManager.AppSettings["name"];

Web.config示例:

  Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Remove("name");
config.Save();
string str1=WebConfigurationManager.AppSettings["name"];

四。读取

1)App.config示例:

 string str=ConfigurationManager.AppSettings["name"];

2)Web.config示例:

 string str=WebConfigurationManager.AppSettings["color"];

五。修改

App.config示例:

         Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["name"].Value = "李四";
config.Save();
string str = ConfigurationManager.AppSettings["name"];

Web.config示例:

         Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
config.AppSettings.Settings["name"].Value = "李四";
config.Save();
string str = ConfigurationManager.AppSettings["name"];

最新文章

  1. java function retry wrapper
  2. 使用HTML5新支持的搭建WebRtc环境来作为视频通讯
  3. CentOS防火墙问题
  4. javascript设计模式实践之代理模式--图片预加载
  5. js快速排序方法
  6. Web Api其中的PUT功能演示
  7. Java完成最简单的WebService创建及使用(REST方式,Jersey框架)
  8. hdu 4163 Stock Prices 水
  9. Aggressive cows 二分不仅仅是查找
  10. 一次完整的http请求所需要完成的步骤
  11. div footer标签css实现位于页面底部固定
  12. beanutils中Lazy
  13. RoundedImageView使用吐槽心得(RoundedImageView与Glide加载图片,第一次加载无法圆角问题)
  14. 201521123040《Java程序设计》第1周学习总结
  15. angularjs bind与model配合双向绑定 表达式方法输出
  16. 实现string到double的转换
  17. Java实现附近地点搜索
  18. java 新手指南
  19. LaTeX入门
  20. VsCode云端版本

热门文章

  1. 编程模式之观察者模式(Observer)
  2. css 去除点击之后的虚线
  3. ArcGIS Engine 刷新问题
  4. java中 DigestUtils.md5Hex 的c#实现
  5. 介绍一款非常适合做微网站并且免费的CMS系统
  6. 循序渐进Python3(十)-- 0 -- RabbitMQ
  7. $.grep(array, callback, [invert])过滤,常用
  8. 【项目】搜索广告CTR预估(二)
  9. myeclipse 手动安装 lombok
  10. TCP数据包的封包和拆包