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

首頁 > 編程 > .NET > 正文

.net 讀取非標準配置文件的小例子

2024-07-10 12:44:51
字體:
來源:轉載
供稿:網友
代碼如下:
代碼如下:
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; 
       } 

配置文件目錄結構:
代碼如下:
<?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"); 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 得荣县| 都安| 荔波县| 偏关县| 南靖县| 遂川县| 东乡族自治县| 贵德县| 黑水县| 吉林市| 辽宁省| 永康市| 于都县| 绥阳县| 柳河县| 扶沟县| 兴业县| 雷州市| 阿勒泰市| 通辽市| 剑阁县| 乌海市| 新津县| 房产| 太仆寺旗| 张家界市| 南皮县| 宁阳县| 绥德县| 息烽县| 呼图壁县| 江西省| 聊城市| 云梦县| 梧州市| 灵丘县| 肇州县| 齐河县| 湖北省| 嘉峪关市| 南涧|