views:

387

answers:

1

Does anyone know how to detect if an instance of a configuration section exists in a .net configuration file without actually having to load the configuration section into memory, and without having to parse the xml file manually - ie, using the System.Configuration namespace.

I have tried using System.Configuration.ConfigurationManager.GetSection(...) but this seems to return a "defaulted" instance of the configuration section, even if it does not exist in the configuration file.

+1  A: 

if you are using local config files (as opposed to machine specific) then you could use XML (such as linq to xml) to check the config file by geting the exe codebase from reflection (e.g. Assembly.GetExecutingAssembly().CodeBase)

Preet Sangha