- Namespace: using System.Configuration;
- Make sure to add the System.Configuration on the References of the solution file if it’s not yet added.
Sample web.config AppSettings keys and values:
Sample Dog Class
Sample usage on a web form’s drop down list
Sample ASPX
private Dog[] ListOfDogs
{
get
{
var appSettings = ConfigurationManager.AppSettings.AllKeys.Where(key => key.StartsWith(“Dog:”));
Dog[] dogs = new Dog[appSettings.Count()];
int i = 0;
foreach (String s in appSettings)
{
dogs [i] = new Dog();
dogs [i].key = s.Replace(“Dog:”,string.Empty);
dogs [i].value = ConfigurationManager.AppSettings[s];
i++;
}
return dogs;
}
}
Result
Leave a comment