reading from app.config file

后端 未结 8 2354
不知归路
不知归路 2020-11-29 19:34

I am trying to read StartingMonthColumn and CategoryHeadingColumn from the below app.config file using the code

ConfigurationSettings.AppSettings[\"StartingM         


        
相关标签:
8条回答
  • 2020-11-29 20:18

    ConfigurationSettings.AppSettings is deprecated, see here:

    http://msdn.microsoft.com/en-us/library/system.configuration.configurationsettings.appsettings.aspx

    That said, it should still work.

    Just a suggestion, but have you confirmed that your application configuration is the one your executable is using?

    Try attaching a debugger and checking the following value:

    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
    

    And then opening the configuration file and verifying the section is there as you expected.

    0 讨论(0)
  • 2020-11-29 20:21

    This:

    Console.WriteLine( "StartingMonthColumn is {0}", ConfigurationManager.AppSettings["StartingMonthColumn"]);
    

    works fine for me.

    Note that ConfigurationManager is in the System.Configuration namespace (so you'll likely want a using System.Configuration; statement), and that since what you read in has a string type you'll need to parse what you read in to use it as a number.

    Also, be sure you set system.configuration.dll as a reference in your project or build script.

    0 讨论(0)
提交回复
热议问题