To configure the C # foreground screen through a configuration file, Curiosity did the following: a new app. config and app1.config two profiles were created in the project,
If you want to read the configuration information from App1.config, how should I read it?
Using the Configurationmanager.appsettings property seems to only read configuration information to App. CONFIG.
ExeconfigurationfilemapMap= New Execonfigurationfilemap();Map.Execonfigfilename = @"D:\App1.config";This corresponds to the path of your App1 file. ConfigurationConfig= ConfigurationManager.Openmappedexeconfiguration(Map, ConfigurationUserLevel.None); StringConnStr=Config.ConnectionStrings.ConnectionStrings[ "connstr" ]. Connectionstring; messagebox. Showconnstrstring key = Config.< Span class= "Typ" >appsettings. Settings[ "key" ]. Value; messagebox. Showkey
/span>
usingSystem;usingSystem.Configuration;namespacejaday.frame.common{ Public classConfigHelper {/// <summary> ///gets the value of the Webconfig specified key/// </summary> /// <param name= "key" >Specify key</param> /// <param name= "defaultvalue" >This value is returned when the obtained value is null</param> /// <returns></returns> Public Static stringGetappsettings (stringKeystringDefaultValue ="") { varValue = Configurationmanager.appsettings[key];//Gets the specified configuration information returnValue = =NULL?Defaultvalue:value. Tostringvalue (); } /// <summary> ///gets the value of the Webconfig specified key/// </summary> /// <param name= "name" >Specify a name</param> /// <param name= "defaultvalue" >This value is returned when the obtained value is null</param> /// <returns></returns> Public Static stringGetConnectionString (stringNamestringDefaultValue ="") { //Gets the specified configuration information varValue =Configurationmanager.connectionstrings[name]. ConnectionString; returnValue = =NULL?Defaultvalue:value. Tostringvalue (); } /// <summary> ///gets the value of the specified key for the configuration file in App_Data/// </summary> /// <param name= "key" >Key</param> /// <param name= "defaultvalue" >Default Value</param> /// <returns></returns> Public Static stringGetappdataappsettings (stringKeystringDefaultValue ="") { varMap =NewExeconfigurationfilemap {execonfigfilename= AppDomain.CurrentDomain.BaseDirectory +"\\App_Data\\App.config" }; varConfig =configurationmanager.openmappedexeconfiguration (map, Configurationuserlevel.none); varValue =CONFIG. Appsettings.settings[key]. Value; returnValue = =NULL?Defaultvalue:value. Tostringvalue (); } /// <summary> ///get the data connection string in App_Data/// </summary> /// <param name= "name" >Data Connection Name</param> /// <param name= "defaultvalue" >Default Value</param> /// <returns></returns> Public Static stringGetappdataconnectionstring (stringNamestringDefaultValue ="") { varMap =NewExeconfigurationfilemap {execonfigfilename= AppDomain.CurrentDomain.BaseDirectory +"\\App_Data\\App.config" }; varConfig =configurationmanager.openmappedexeconfiguration (map, Configurationuserlevel.none); varValue =CONFIG. Connectionstrings.connectionstrings[name]. ConnectionString; returnValue = =NULL?Defaultvalue:value. Tostringvalue (); } }}
The project file contains two config files, app. config and app1.config, how to get the configuration in App1.config