手机
当前位置:查字典教程网 >编程开发 >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 读取非标准配置文件的小例子】相关文章:

asp.net AJAX实现无刷新获得数据

asp.net 获取指定文件夹下所有子目录及文件(树形)

.net发送邮件实现代码

asp.net Xml绑定到数据控件的具体实现

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

asp.net文件上传示例

asp.net通过配置文件连接Access的方法

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

使用linq读取分隔符文本文件

asp.net Repeater绑定时使用函数

精品推荐
分类导航