I have appSetting block that looks like this:
<appSettings>
<key="site1" value="http://www.thissite.com,site name" />
<key="site2" value="http://www.thissite.com,site name" />
</appSettings>
I want to populate a dropdown list with the values and text:
value=”http://www.thissite.com” text=”site name”
I can get them into individual arrays using this:
string[] mykey = ConfigurationManager.AppSettings["site1"].Split(',');
string[] mykey = ConfigurationManager.AppSettings["site2"].Split(',');
however, I want to combine them into one array and then loop through and populate the dropdown in the codebehind. I can populate it this way looping through the individual arrays, but it just seems as if there must be a better way with less code.
Can anyone tell me how?
credit to you all but many thanks to acermate433s’ answer below.
NameValueCollection appSettings = ConfigurationManager.AppSettings;
for (int i = 0; i < appSettings.Count; i++)
{
Response.Write(appSettings.GetKey(i).ToString() + "-" + appSettings[i].ToString());
}
Obviously, I will do a bit more than just display it.
AppSettings is a NameValueCollection, you could loop through all of its values using for each