[RESOLVED] How do I get a value for a key using the KeyValueConfigurationElement?
Here's my code to get the three parameters from a configuration!
C# Code:
Configuration configuration = ConfigurationManager.OpenExeConfiguration(dllConfigFile);
var appSettings = configuration.AppSettings.Settings;
foreach (KeyValueConfigurationElement keyValueConfigurationElement in appSettings)
{
switch(keyValueConfigurationElement.Key)
{
case "WSUser": UserId = keyValueConfigurationElement.Value;
break;
case "WSUserPassword": UserPassword = keyValueConfigurationElement.Value;
break;
case "endpointurl": EndPointUrl = keyValueConfigurationElement.Value;
break;
}
}
I want to eliminate the loop completely and just go after the specific key. I know the key names, so what is the syntax to do this?
Re: How do I get a value for a key using the KeyValueConfigurationElement?
Your appSettings variable should be a dictionary of some sort, so you can simply index it with the appropriate key to get the appropriate value.
Re: How do I get a value for a key using the KeyValueConfigurationElement?
Found it.
UserId = appSettings["WSUser"].Value;