Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Access the ConfigSection of specified config file

Access the ConfigSection of specified config file

Scheduled Pinned Locked Moved C#
questioncsharpxmlperformanceannouncement
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndieDu
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups