.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的专栏
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- Add View -> Strongly-typed view ->Model Class
- 让asp.net mvc的Action支持jQuery直接提交的javascript对
- ASP.ENT前台更改绑定数据的日期格式
- Asp.net MVC源码分析--UrlRoutingModule与Service location的
- 使用HttpWebRequest下载经过重定向的文件
- C#高级编程:使用XPath命名空间中的类[2]
- DCOM--高效率主从服务器程序的新概念
- .Net插件框架的实现及分析(二)
- .NET简谈设计模式之(装饰者模式性能问题?)
- .NET类库中发现设计模式:策略模式



