Reputation: 107
can anyone tell me how to get the key name associated with a value in <app settings>
Upvotes: 1
Views: 744
Reputation: 49220
Not entirely clear what you want to achieve here, but you could always just iterate over all appSettings and compare their values. If you find the one you're looking for take it's key.
foreach (string key in Configuration.AppSettings.Settings.AllKeys)
{
string value = appSettings.Settings[key].Value;
if (value.Equals(myValue))
{
Console.WriteLine("Found Key: " + key);
break;
}
}
NOTE: The reverse mapping from value to key is of course not necessarily unique, i.e. you would have to deal with the fact, that the value you're using a search predicate matches more than one key.
Upvotes: 3