手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >.net 读取非标准配置文件的小例子
.net 读取非标准配置文件的小例子
摘要:代码如下:复制代码代码如下:publicstaticstringConfig(stringkey){ExeConfigurationFile...

代码如下:

复制代码 代码如下:

public static string Config(string key)

{

ExeConfigurationFileMap file = new ExeConfigurationFileMap();

file.ExeConfigFilename = @"ProvidersProvider.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");

【.net 读取非标准配置文件的小例子】相关文章:

.net发送邮件实现代码

.net下实现Word动态填加数据打印

.net获取本机公网IP地址示例

介绍asp.net 操作INI文件的读写

asp.net简化接收参数值的函数

asp.net 事件与委托分析

asp.net Repeater绑定时使用函数

ConfiguraionSource节点及多个配置文件的应用

.net自定义事件示例分享

第一次用.net2.0 LOGIN登陆控件的困惑和解决方法

精品推荐
分类导航