.net 讀取非標(biāo)準(zhǔn)配置文件的小例子
更新時(shí)間:2013年07月30日 10:22:01 作者:
這篇文章介紹了.net 讀取非標(biāo)準(zhǔn)配置文件的小例子,有需要的朋友可以參考一下
代碼如下:
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):
<?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)用:
//里面的參數(shù)為配置文件的key
string strConn=Config("ConnectionString");
復(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");
相關(guān)文章
asp.net運(yùn)行提示未將對象引用設(shè)置到對象的實(shí)例錯(cuò)誤解決方法
asp.net運(yùn)行提示未將對象引用設(shè)置到對象的實(shí)例錯(cuò)誤解決方法,需要的朋友可以參考下2012-03-03Asp.Net如何將多個(gè)RadioButton指定在一個(gè)組中
將多個(gè)RadioButton指定在一個(gè)組中,實(shí)現(xiàn)其實(shí)很簡單,一句代碼即可,具體如下,希望對大家有所幫助2013-12-12mysql安裝后.net程序運(yùn)行出錯(cuò)的解決方法
這篇文章主要給大家介紹了關(guān)于mysql安裝后.net程序運(yùn)行出錯(cuò)的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-02-02asp.net下用js實(shí)現(xiàn)鼠標(biāo)移至小圖,自動(dòng)顯示相應(yīng)大圖
asp.net下用js實(shí)現(xiàn)鼠標(biāo)移至小圖,自動(dòng)顯示相應(yīng)大圖...2007-03-03ASP.NET Core 2.0 使用支付寶PC網(wǎng)站支付實(shí)現(xiàn)代碼
這篇文章主要介紹了ASP.NET Core 2.0 使用支付寶PC網(wǎng)站支付實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-10-10頁面間隔半秒鐘更新時(shí)間 Asp.net使用Comet開發(fā)http長連接示例分享
Comet(Reverse AJAX)主要是通過HTTP長連接, 保持和服務(wù)器的連接,實(shí)現(xiàn)Server PUSH 和雙向通信,下面通過示例學(xué)習(xí)他的使用方法2014-01-01