Here is my config file:
<?xml version="1.0" encoding="utf-8" ?><configuration><configSections><section name="MySection" type="MyApp.MySectionClass, MyApp"/></configSections><MySection name="SomeName" data_type="SomeDataType" file_name="file"> <CollectionName><add name="name1" param="-10" ping="3"/><add name="name1" param="-10" ping="5"/><add name="name2" param="-10" ping="3" param2="0.3" param3="0.2"/></CollectionName></MySection ></configuration>
Here is the code where i try just to have a list of my names of sections in my config file:
ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.ExeConfigFilename = "path\\app.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); ConfigurationSectionCollection section_collection = config.Sections; foreach (string key in section_collection.Keys) Console.WriteLine(key);
Here what i get as a result:
system.data.sqlclient connectionStrings system.webServer system.data.dataset satelliteassemblies mscorlib startup runtime appSettings system.data.odbc system.data configProtectedData system.codedom uri system.runtime.remoting assemblyBinding windows system.data.oracleclient MySection system.windows.forms system.diagnostics system.data.oledb
As you can see there is my section name, but also a lot of other namespaces. Why does it happen? How can i get only my custom sections from app.config? I don't know sections' names and number of them beforehand. That's why i want to iterate over the section collection.
Thanks.