Thursday, August 27, 2009

Reading Data from the Configuration (*.config) File

In the previous post I saved data to the config file. Here is an example of how you would read data from the config file:
if (ConfigurationManager.AppSettings["Width"] != null)
{
    this.Width = Convert.ToDouble(ConfigurationManager.AppSettings["Width"]);
}

if (ConfigurationManager.AppSettings["Height"] != null)
{
    this.Height = Convert.ToDouble(ConfigurationManager.AppSettings["Height"]);
}


More Info: MSDN: ConfigurationManager.AppSettings