While doing some updates to the EmmCLA program (more to come on this soon), I needed to have it loop through all the AppSettings in in App.Config file (the same should hold true for Web.Config for web apps) to find all occurrences of appsettings that were similar to a certain string.
A few Google searches later led me to the solution of using System.Configuration.ConfigurationSettings.AppSettings.AllKeys which returns a string array of all the keys in the AppSettings portion of App.Config:
// Loop through all AppSetting keys to find those
// matching DBConn-xxxxstring[] AppSettings = ConfigurationSettings.AppSettings.AllKeys;foreach (string s in AppSettings){if (s.ToLower().Contains("dbconn-")){
// Do Something Here
}}
I’ve posted this in case anyone else finds a need to do something similar. This saved me a great deal of work and hopefully someone else will similarly benefit.
If you find this of some benefit, please leave us a comment below and let us know how you are using it.
- Setting up SSL on Amazon Linux Instance under EC2 - July 26, 2018
- Method Chaining of Objects in C# - January 16, 2017
- Native SQL Backup And Restores on AWS RDS - November 9, 2016