- VBForums
- .NET and More
- C#
- 3.0/LINQ [RESOLVED] How do I get a value for a key using the KeyValueConfigurationElement?
-
Nov 29th, 2011, 10:39 AM
#1
[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?
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Nov 29th, 2011, 09:48 PM
#2
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.
-
Dec 1st, 2011, 05:02 PM
#3
Re: How do I get a value for a key using the KeyValueConfigurationElement?
Found it.
UserId = appSettings["WSUser"].Value;
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
- VBForums
- .NET and More
- C#
- 3.0/LINQ [RESOLVED] How do I get a value for a key using the KeyValueConfigurationElement?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|