读取配置config文件
2016-04-26 18:16
405 查看
<system.net> <mailSettings> <smtp from="Fish.Q.Li@newegg.com"> <network /> </smtp> </mailSettings> </system.net>
读取上面↑的xml代码{
mtpSection section = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; labMailFrom.Text = "Mail From: " + section.From;
}
写入配置文件:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); SmtpSection section = config.GetSection("system.net/mailSettings/smtp") as SmtpSection; section.From = "Fish.Q.Li@newegg.com2"; config.Save();
如果配置文件为以下格式的:
<MySection444> <add key="aa" value="11111"></add> <add key="bb" value="22222"></add> <add key="cc" value="33333"></add> </MySection444>
读取方法:
<sinosoft> <esb> <headers> <children> <header service="s-1" version="1" consumer="CS-1/65/" password="12436798" desc=""></header> <header service="s-2" version="1" consumer="CS-1/6" password="4235465687" desc=""></header> <header service="s-3" version="1" consumer="CS-1/-01" password="24346" desc=""></header> </children> </headers> </esb> <reports> <sms url="" userid="TCBB" password="456"></sms> </reports> </sinosoft>
View Code
小结:
1. 为每个集合中的参数项创建一个从ConfigurationElement继承的派生类。
2. 为集合创建一个从ConfigurationElementCollection继承的集合类,具体在实现时主要就是调用基类的方法。
3. 在创建ConfigurationSection的继承类时,创建一个表示集合的属性就可以了,注意[ConfigurationProperty]的各参数。
参考自:http://www.cnblogs.com/fish-li/archive/2011/12/18/2292037.html#_labelStart
相关文章推荐
- codeforces 668C - Little Artem and Random Variable
- lamp整合三连发(3)
- Tyvj_P1018
- LBP特征
- Linux下tmpfs与ramfs的区别
- Android学习路线总结,绝对干货
- The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
- C++实验4-穷举法解决百钱买百鸡
- 编译安装nginx的参数
- oracle中的条件是rownum=1就取第一个数,那我现在要第2个,要怎么写或者用其他条件拿到第2个,且只要第2个
- 第四次作业
- 关于iOS的App上线,纯自用,mark
- 分析java程序的运行过程
- 【翻译】Xibo官方文档3-Windows Client Installation
- 【创业记】前言
- 【翻译】Xibo官方文档2-CMS Installation
- 【翻译】XIBO官方文档1-Introduction
- 【极光推送】给指定用户发送消息
- 【极光推送】jpush服务端开发详尽过程
- 【转载】极光推送 使用实例 (一)服务端