title: Loop through different sections of appConfig file
body: <p>I have an AppConfig file as shown below. I am trying to loop through the configsections and get the section name, based on the section name, it should select the appropriate appSettings. For example, when the first section is VehicleConfig, it should automatically select the appSettings of VehicleConfig. I need this automatic selection because i have multiple sections and I have to get the appSettings of different sections based on their section names.</p>
  
  <pre><code>    &lt;configuration&gt;
       &lt;configSections&gt;
        &lt;sectionGroup name = "mySection"&gt;
         &lt;section name="VehicleConfig"/&gt;
         &lt;section name="LiveDownloaderConfig"/&gt;
        &lt;/sectionGroup&gt;
       &lt;/configSections&gt;
       &lt;VehicleConfig&gt;
         &lt;appSettings&gt;
           &lt;add key="FileRoot" value="C:\FilesToUpload" /&gt;
           &lt;add key="Project" value="BigDataTest" /&gt;
           &lt;add key="Dataset" value="StoreServer" /&gt;
         &lt;/appSettings&gt;
       &lt;/VehicleConfig&gt;
       &lt;LiveDownloaderConfig&gt;
         &lt;appSettings&gt;
          &lt;add key="FileRoot" value="C:\FilesToUpload" /&gt;
          &lt;add key="Project" value="BigDataTest" /&gt;
          &lt;add key="Dataset" value="BQSMeasure" /&gt;
         &lt;/appSettings&gt;
       &lt;/LiveDownloaderConfig&gt;
    &lt;/configuration&gt;
  </code></pre>
  
  <p>I have tried this code and when the second for-each loop is hit, it throws the error "Unrecognized element appSettings inside VehicleConfig". I tried removing the appSettings, but then it throws "Unrecognized element add". I wonder whether i can have these elements inside VehicleConfig.</p>
  
  <pre><code> System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  
   ConfigurationSectionGroupCollection sectionGroups = config.SectionGroups;
  
           foreach (ConfigurationSectionGroup group in sectionGroups)
          // Loop over all groups
          {
              Console.WriteLine(group);
              if (group.Name == "FileCheckerConfigGroup")
              {
                  foreach (ConfigurationSection configurationSection in group.Sections)
                  {
                      var section = ConfigurationManager.GetSection(configurationSection.SectionInformation.SectionName) as NameValueCollection;
                  }
              }
          }
  </code></pre>
  
  <p>Any help is appreciated !!</p>