The Code is as follows:
Copy codeThe Code is as follows:
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;
}
Configuration file directory structure:
Copy codeThe Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Deleetask>
<Add key = "ConnectionString" value = "Server = (local); Database = DB; User Id = sa; Password = 123"/>
</AppSettings>
</Configuration>
Call:
Copy codeThe Code is as follows:
// The parameter is the key of the configuration file.
String strConn = Config ("ConnectionString ");