.net 读取非标准配置文件
代码如下:
public static string Config(string key)
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = @"Providers\\Provider.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");
return appsection.Settings[key].Value;
}
配置文件目录结构:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Server=(local);Database=DB;User Id=sa;Password=123" />
</appSettings>
</configuration>
调用:
//里面的参数为配置文件的key
string strConn=Config("ConnectionString");
摘自 tommy的专栏
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- .NET设计模式:工厂方法模式(Factory Method)[1]
- MVC3+Entity Framework 实现投票系统(二)
- JQuery+Asp.net MVC实现用户名重名查询
- 使用ASP.NET MVC3+EF+Jquery制作文字直播系统(四
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注
- 聊聊.net程序设计——浅谈使用VS2010建模拓展(下
- .net架构的最后思考(箴言)
- .NET简谈互操作(四:基础知识之Dispose非托管内存
- Web Service学习笔记(4)
- asp.net DataTable和Dataset序列化成Json格式



