代碼如下
public static string Config(string key)
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file
Configuration config = ConfigurationManager
AppSettingsSection appsection = (AppSettingsSection)config
return appsection
}
配置文件目錄結構
<?xml version="
<configuration>
<appSettings>
<add key="ConnectionString" value="Server=(local);Database=DB;User Id=sa;Password=
</appSettings>
</configuration>
調用
//裡面的參數為配置文件的key
string strConn=Config("ConnectionString");
From:http://tw.wingwit.com/Article/program/net/201311/14052.html