App.config
Dear Techies
I am developing a windows application in VB.net 2008. The applications login form has a drop down which represents different environments like System Test, Acceptance Test, Production, Development etc. When I select a particular region the corresponding connection string should be read from the config file. My challenge here is teh combo box representing various regions should also be loaded from the app.config file. Is there any way we can loop through keys in app.config fle?
Right now I have handled it in the follwoing way
<add key="Environments" value="Production|Acceptance|System Testing|Development/>
<add key="Production" value="connectionstring to production goes here"/>
<add key="Development" value="connectionstring to development goes here"/>
<add key="Acceptance" value="connectionstring to Acceptance goes here"/>
I read the environments key in the code and split it in to an array based on | (pipe) character. Then this array is assigned to the data source of the combo box which will populate the combo box with region names. When I select a value from teh combo box corresponding key from the app.config will be read. I am looking for a better method for the same purpse. Hope every one understood my intention. Please advice
Regards
Jayaraj Sivadasan
jayaraj- Moved bySylvester-MSFTMSFTFriday, November 06, 2009 4:18 AMNot POS specific question (From:POS for .NET)
Answers
- Hi,
This code snippet may show some lights to you about how to go through all keys and their values in app.config:
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
foreach (string key in config.AppSettings.Settings.AllKeys)
{
Console.WriteLine("{0} --> {1}", key, config.AppSettings.Settings[key]);
}
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorTuesday, November 10, 2009 9:15 AM
All Replies
- Hi,
This code snippet may show some lights to you about how to go through all keys and their values in app.config:
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
foreach (string key in config.AppSettings.Settings.AllKeys)
{
Console.WriteLine("{0} --> {1}", key, config.AppSettings.Settings[key]);
}
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorTuesday, November 10, 2009 9:15 AM


