Access the ConfigSection of specified config file
-
Dear All ConfigurationManager.GetSection("Section1") only retrieve the default app.config's section information and it returns a object that can be casted. Now i have a specified configuration that used by my application. I have loaded the specified configuration file into the memory, please see the below code: this is the specified config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="Section1" type="CortexShell.DisplayModeSectionHandler,CortexShell" />
</configSections>
<Section1 DisplayMode="MonitorDisplay" Timeout="300" />
</configuration>this is the c# code:
Configuration config = ConfigurationManager.OpenExeConfiguration(@"c:\AppState.config");
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = path;
config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
DisplayModeSection _displayMode = (DisplayModeSection)config.GetSection("Section1");Now the config.GetSection("Section1") only returns the specified configuration.ConfigurationSection object, hence when i compile it, this is the exception: Cannot convert type 'System.Configuration.ConfigurationSection' to 'CortexShell.DisplayModeSection', my question is how can i convert System.Configuration.ConfigurationSection to CortexShell.DisplayModeSection (this is my customised config section in the specified config file) Thanks very much