您现在的位置是:网站首页> 编程资料编程资料
.net 读取非标准配置文件的小例子_实用技巧_
2023-05-24
344人已围观
简介 .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;
}
配置文件目录结构:
调用:
//里面的参数为配置文件的key
string strConn=Config("ConnectionString");
复制代码 代码如下:
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;
}
配置文件目录结构:
复制代码 代码如下:
调用:
复制代码 代码如下:
//里面的参数为配置文件的key
string strConn=Config("ConnectionString");
您可能感兴趣的文章:
