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

NewBie picture NewBie · Jul 21, 2011 · Viewed 80.5k times · Source

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>

Answer

Andreas &#197;gren picture Andreas Ågren · Jul 21, 2011

ConfigurationSettings.AppSettings are obsolete, try

ConfigurationManager.AppSettings["ShowQueryTextbox"];