手机
当前位置:查字典教程网 >编程开发 >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发送邮件实现代码

ASP.NET Web API标准的“管道式”设计

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

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

litjson读取数据示例

在ASP.NET2.0中通过Gmail发送邮件的代码

asp.net中获取远程网页的内容之一(downmoon原创)

asp.net文件上传示例

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

asp.net模板引擎Razor调用外部方法用法实例

精品推荐
分类导航