The project file contains two config files, app. config and app1.config, how to get the configuration in the App1.config

Source: Internet
Author: User
Tags connectionstrings

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.