Monday, September 24, 2012

Reading Information from a webconfig file in

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 -->
    <add key="NameOfTheKey" value="Value"/>
    <add key="FooKey" value="\\folder\Shared Documents"/>

Here is how to get the file in C#

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

Hope that helps