Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:05:53+00:00 2026-05-24T12:05:53+00:00

my desired app.config would be like this: <configSections> <sectionGroup name=QA_Environment> <section name=databases type=System.Configuration.NameValueSectionHandler/> <section

  • 0

my desired app.config would be like this:

<configSections>
        <sectionGroup name="QA_Environment">
            <section name="databases" type="System.Configuration.NameValueSectionHandler"/>
            <section name="storageSystems" type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
        <sectionGroup name="Production_Environment">
            <section name="databases" type="System.Configuration.NameValueSectionHandler"/>
            <section name="storageSystems" type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
    </configSections>

…and then I’ve got the actual groups and sections right below that. But I’d be happy with whatever works or better suggestions though. I’ve now lowered my wishes to this:

    <configSections>
    <sectionGroup name="QA_Environment">
        <section name="appSettings" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
    <sectionGroup name="Production_Environment">
        <section name="appSettings" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
</configSections>

And I guess that’s fine…The main thing I’m wondering about is if I can substitute one of these sections as the root level appSettings…without iterating through them and programmatically adding or creating the config and saving it. I just want the user to be able to select an environment, the select event will change the appSettings…

One constraint that I’m facing is that the data layer I’m referencing needs to remain the same as it is….so I basically need to get my app.config to be accessible exactly like it is currently from these other projects…that is ConfigurationManager.AppSettings[afdasdf]

Let me know if this needs any clarification…thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:05:54+00:00Added an answer on May 24, 2026 at 12:05 pm

    I’ll go ahead and answer my own question here if that’s alright. I found that I was making it much harder than it really is. All you have to do is this:

    <?xml version="1.0" encoding="utf-8"?>
    

    <configSections>
        <sectionGroup name="Environment">
            <sectionGroup name="QA">
                <section name="databases" type="System.Configuration.DictionarySectionHandler"/>
                <section name="storageSystems" type="System.Configuration.DictionarySectionHandler"/>
            </sectionGroup>
            <sectionGroup name="PROD">
                <section name="databases" type="System.Configuration.DictionarySectionHandler"/>
                <section name="storageSystems" type="System.Configuration.DictionarySectionHandler"/>
            </sectionGroup>
        </sectionGroup>
    </configSections>
    
    <Environment>
        <QA>
            <databases>
            </databases>
            <storageSystems>
            </storageSystems>
        </QA>
    
        <PROD>
            <databases>
            </databases>
            <storageSystems>
            </storageSystems>
        </PROD>
    </Environment>
    

    So there’s part of my app.config….the rest is just as easy:

    private void GetConfigurationSettings(TargetEnvironments targetEnvironment)
        {
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var databases = new Hashtable();
            var storageSystems = new Hashtable();
    
            switch (targetEnvironment)
            {
                case TargetEnvironments.QA:
                    databases = (Hashtable)ConfigurationManager.GetSection("Environment/QA/databases");
                    storageSystems = (Hashtable)ConfigurationManager.GetSection("Environment/QA/storageSystems");
                    break;
                case TargetEnvironments.PROD:
                    databases = (Hashtable)ConfigurationManager.GetSection("Environment/PROD/databases");
                    storageSystems = (Hashtable)ConfigurationManager.GetSection("Environment/PROD/storageSystems");
                    break;
            }
    
            foreach (string key in databases.Keys) { config.AppSettings.Settings.Add(key, databases[key].ToString()); }
            foreach (string key in storageSystems.Keys) { config.AppSettings.Settings.Add(key, storageSystems[key].ToString()); }
    
            config.Save(ConfigurationSaveMode.Modified);
    
            ConfigurationManager.RefreshSection("appSettings");
    
            UpdateCollections();
        }
    

    Note the obviously important use of the config.Save method to immediately load the settings that you’ve just set. Other than that, it’s really just the path names and the section type that I had to kinda decide on. I found the link below to be the most useful. If someone’s got a more elegant way I’d be interested to hear about it.

    Here’s the place I got the most out of in my research

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client whose desired Web UI is graphically intense; we would like
I have an ASP.Net application which as desired feature, users would like to be
I have this query that works as desired, but it seems like there should
A coworker has been struggling with this problem. The desired result is an installable
I want to create a web app with a desired release date of fall-winter
This app has multiple activities: eg: Activity1 -> Activity2 -> Activity3. If the app
I have an iPhone app that use UIPickerView and 3 buttons. This picker has
I'm writing an app, that has a somewhat modular system. It has a core
in this app, the user logs in and their credentials are checked against a
I need a graphical needle gauge (like a speedometer etc) for my app but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.