.net 讀取非標準配置文件的小例子
更新時間:2013年07月30日 10:22:01 作者:
這篇文章介紹了.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;
}
配置文件目錄結(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運行提示未將對象引用設(shè)置到對象的實例錯誤解決方法
asp.net運行提示未將對象引用設(shè)置到對象的實例錯誤解決方法,需要的朋友可以參考下2012-03-03Asp.Net如何將多個RadioButton指定在一個組中
將多個RadioButton指定在一個組中,實現(xiàn)其實很簡單,一句代碼即可,具體如下,希望對大家有所幫助2013-12-12asp.net下用js實現(xiàn)鼠標移至小圖,自動顯示相應(yīng)大圖
asp.net下用js實現(xiàn)鼠標移至小圖,自動顯示相應(yīng)大圖...2007-03-03ASP.NET Core 2.0 使用支付寶PC網(wǎng)站支付實現(xiàn)代碼
這篇文章主要介紹了ASP.NET Core 2.0 使用支付寶PC網(wǎng)站支付實現(xiàn)代碼,需要的朋友可以參考下2017-10-10頁面間隔半秒鐘更新時間 Asp.net使用Comet開發(fā)http長連接示例分享
Comet(Reverse AJAX)主要是通過HTTP長連接, 保持和服務(wù)器的連接,實現(xiàn)Server PUSH 和雙向通信,下面通過示例學(xué)習(xí)他的使用方法2014-01-01