This code provides an easy to use mechanism for reading
ppSettings values from the Web.Config in non web based environments. Additionally there is a very simple form that demonstrates the code being used.
I have worked on many solutions that have comprised of Web projects together with Console or Windows applications. Often the need has arisen for the non web components to be able to read values from the Web.Config file (particularly in automated testing environments) so I wrote a class to simplify this and present it here.
Using the code
The code is designed to be very close in syntax to the usual method used for accessing web.config from a web app. Pass the constructor the location of the web.config file you wish to parse and then use the
AppSettings method to obtain the desired value; an exception will be thrown should it not be found
string filename = @"c:\temp\Web.Config";
UK.Org.Webman.ConfigurationSettings ConfigurationSettings =
string PrimaryDatabase = ConfigurationSettings.AppSettings["PrimaryDatabase"];