Monday, September 24, 2012

Reading Information from a webconfig file in asp.net

Every once in a while, we would like to keep some of the application settings in a web config file to handle tasks like Database location and file location. Here is a quick way too read from a Web.config file  

<!-- Somewhere in the web.config fole -->
  <appSettings>
    <add key="NameOfTheKey" value="Value"/>
    <add key="FooKey" value="\\folder\Shared Documents"/>
  </appSettings>


Here is how to get the file in C#


string location = WebConfigurationManager.AppSettings["NameOfTheKey"]; //location will be "Value"

Hope that helps

No comments :

Post a Comment