国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net 讀取非標(biāo)準(zhǔn)配置文件的小例子

2020-01-17 23:48:22
字體:
供稿:網(wǎng)友
代碼如下:
復(fù)制代碼 代碼如下:

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; 
       } 

配置文件目錄結(jié)構(gòu):
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <appSettings> 
        <add key="ConnectionString" value="Server=(local);Database=DB;User Id=sa;Password=123" /> 
    </appSettings> 
</configuration> 

調(diào)用:
復(fù)制代碼 代碼如下:

//里面的參數(shù)為配置文件的key  
string strConn=Config("ConnectionString"); 
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 安远县| 德阳市| 丹东市| 泰宁县| 原阳县| 娄烦县| 天门市| 东乡族自治县| 蕲春县| 云林县| 榕江县| 荔浦县| 阳谷县| 博爱县| 邯郸市| 赫章县| 黄梅县| 桃园市| 静宁县| 灌阳县| 大宁县| 商水县| 阳高县| 突泉县| 鄂托克旗| 绥江县| 文水县| 浙江省| 辉县市| 高阳县| 连山| 玉溪市| 重庆市| 调兵山市| 晋中市| 柘城县| 博野县| 任丘市| 四会市| 九龙城区| 招远市|