For some reason I have

For some reason I have a mental block on the syntax required to get information from the Web.config file in a .Net web application. Its not difficult, you just need to include the System.Configuration name space with a using statement in the header of the C# code behind page. Then you can access any of your configuration values from the static property AppSettings in the ConfigurationSettings class. The AppSettings property is a NameValueCollection. So you can retrieve a particular value using its key.

Example:


using System.Configeration;

string path = ConfigerationSettings.AppSettings[“NA_PATH”];


Example web.config file:



<configuration>

<appSettings>
<add key=”NA_PATH” value=”D:\documents\engineering\” />
</appSettings>
</configuration>


Leave a comment