没有合适的资源?快使用搜索试试~ 我知道了~
首页ASP.NET(C#)应用程序配置文件app.config/web.config的增、删、改操作
配置文件,对于程序本身来说,就是基础和依据,其本质是一个xml文件,对于配置文件的操作,从.NET 2.0 开始,就非常方便了,提供了 System [.Web] .Configuration 这个管理功能的NameSpace,要使用它,需要添加对 System.configuration.dll的引用。 对于WINFORM程序,使用 System.Configuration.ConfigurationManager; 对于ASP.NET 程序, 使用 System.Web.Configuration.WebConfigurationManager; 对于配置文件内容的读取,真是太普遍不过了,
资源详情
资源评论
资源推荐
ASP.NET(C#)应用程序配置文件应用程序配置文件app.config/web.config的的
增、删、改操作增、删、改操作
配置文件,对于程序本身来说,就是基础和依据,其本质是一个xml文件,对于配置文件的操作,从.NET 2.0 开始,就非常方
便了,提供了 System [.Web] .Configuration 这个管理功能的NameSpace,要使用它,需要添加对 System.configuration.dll的
引用。
对于WINFORM程序,使用 System.Configuration.ConfigurationManager;
对于ASP.NET 程序, 使用 System.Web.Configuration.WebConfigurationManager;
对于配置文件内容的读取,真是太普遍不过了,如果你的程序里,没有读取配置文件内容的方面,你都不好意思拿出来用
我们以最常见的 AppSettings 小节来作为例子:
假设有如下的配置文件内容:
代码如下:
<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<appSettings>
<add key=”y” value=”this is Y”/>
</appSettings>
</configuration>
1. 读取值:读取值:
* Asp.Net: System.Web.Configuration.WebConfigurationManager.AppSettings[“y”];
* WinForm: System.Configuration.ConfigurationManager.AppSettings[“y”];
2. 添加一项添加一项
ASP.NET(需要有写权限):
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Add(“x”, “this is X”);
config.Save(ConfigurationSaveMode.Modified);
WinForm:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection app = config.AppSettings;
app.Settings.Add(“x”, “this is X”);
config.Save(ConfigurationSaveMode.Modified);
3. 修改一项修改一项
* Asp.Net
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
//app.Settings.Add(“x”, “this is X”);
app.Settings[“x”].Value = “this is not Y”;
config.Save(ConfigurationSaveMode.Modified);
* WinForm
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection app = config.AppSettings;
//app.Settings.Add(“x”, “this is X”);
app.Settings[“x”].Value = “this is not Y”;
config.Save(ConfigurationSaveMode.Modified);
4. 删除一项删除一项
* Asp.Net
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Remove(“x”);
config.Save(ConfigurationSaveMode.Modified);
* WinForm
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection app = config.AppSettings;
app.Settings.Remove(“x”);
config.Save(ConfigurationSaveMode.Modified);
您可能感兴趣的文章您可能感兴趣的文章:详解C#App.config和Web.config加密c# 配置文件App.config操作类库的方法c#读写
App.config,ConfigurationManager.AppSettings 不生效的解决方法VS中C#读取app.config数据库配置字符串的三种方法C#加
密app.config中连接字符串的方法C#中读取App.config配置文件代码实例C#读写操作app.config中的数据应用介绍C#获取
App.Config配置项的方法总结
weixin_38504170
- 粉丝: 3
- 资源: 937
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 2023年中国辣条食品行业创新及消费需求洞察报告.pptx
- 2023年半导体行业20强品牌.pptx
- 2023年全球电力行业评论.pptx
- 2023年全球网络安全现状-劳动力资源和网络运营的全球发展新态势.pptx
- 毕业设计-基于单片机的液体密度检测系统设计.doc
- 家用清扫机器人设计.doc
- 基于VB+数据库SQL的教师信息管理系统设计与实现 计算机专业设计范文模板参考资料.pdf
- 官塘驿林场林防火(资源监管)“空天地人”四位一体监测系统方案.doc
- 基于专利语义表征的技术预见方法及其应用.docx
- 浅谈电子商务的现状及发展趋势学习总结.doc
- 基于单片机的智能仓库温湿度控制系统 (2).pdf
- 基于SSM框架知识产权管理系统 (2).pdf
- 9年终工作总结新年计划PPT模板.pptx
- Hytera海能达CH04L01 说明书.pdf
- 数据中心运维操作标准及流程.pdf
- 报告模板 -成本分析与报告培训之三.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0