How to get the key value from the AppSettings.Config file?

Viewed 86401

I'm trying to get my key value set in the appsettings.Config file but seems not working.

This is what i wrote for that. The code is called from the constructor of an MDI file and its returning only null value. Anybody know why?

     var getValue = ConfigurationSettings.AppSettings["ShowQueryTextbox"];

I also tried with ConfigurationManager.AppSettings . That too didnt work.

My AppSettings Code is as follows.

<configuration>
  <appSettings>
    <add key="ShowQueryTextbox" value="true"/>
  </appSettings>
</configuration>
8 Answers

The ConfigurationManager is still up to date - Year 2017.

Btw, if you simply want to convert the appsettings configuration value from string to bool, then use Convert.ToBoolean

    if (Convert.ToBoolean(ConfigurationManager.AppSettings["EnableLoggingInfo"]))
    {
        log.Info(message);
    }

In your appsettings configuration (web.config)

<appSettings>
    <add key="EnableLoggingInfo" value="true" />

  </appSettings>
Related