We help IT Professionals succeed at work.

How to read a appSetting C#

mattisflones
mattisflones asked
on
Medium Priority
2,309 Views
Last Modified: 2010-05-19
Hi.

I have a section in web.config like this:
 <appSettings>
    <add key="mailServer" value="localhost" />
    <add key="mailFromAddress" value="testmail@test.server" />
  </appSettings>

How do i read the values?
All the examples i can find is for looping through the values, and thats not what i want.. i need to read one value.
Comment
Watch Question

Commented:
just try


String mailServerValue=ConfigurationSettings.AppSettings("mailServer")

similarly

String mailFromAddress=ConfigurationSettings.AppSettings("mailFromAddress")

Author

Commented:
Nope.. that makes .NET respond with:

"CS0118: 'System.Configuration.ConfigurationSettings.AppSettings' is a 'property' but is used like a 'method'"
Commented:
change the brackets bcos the i code i had was in VB.net.....
String mailFromAddress=ConfigurationSettings.AppSettings["mailFromAddress"]


http://dotnetjunkies.com/Tutorial/F96B2FD6-D06C-4BE1-9167-770ED4990EAA.dcik

look for the error solution in this webpage..

http://dotnetjunkies.com/Tutorial/F96B2FD6-D06C-4BE1-9167-770ED4990EAA.dcik

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Oh for Fks sake... :-)

When will i ever remember that diff. from VB..

Thanks a million!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.