Tuesday, May 01, 2007

ASP : Getting configuration variables from web.config

Instead of hard-coding these in the .cs code, you could use the following:

string inputFile = ConfigurationManager.AppSettings.Get("FileLoc");

In the web.config, in the appSettings section, enter something like:

LSBadd key="FileLoc" value="C:\somewhere\File.xml" /RSB

where:

LSB = Left square bracket
RSB = Right square bracket

You can also do this from Visual Studio when viewing an .aspx page. Click Website / ASP.NET configuration and type in the entries there.

Enjoy!

No comments: