How to read a appSetting C#

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.
LVL 15
mattisflonesAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Pra4444Connect With a Mentor 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
0
 
Pra4444Commented:
just try


String mailServerValue=ConfigurationSettings.AppSettings("mailServer")

similarly

String mailFromAddress=ConfigurationSettings.AppSettings("mailFromAddress")
0
 
mattisflonesAuthor Commented:
Nope.. that makes .NET respond with:

"CS0118: 'System.Configuration.ConfigurationSettings.AppSettings' is a 'property' but is used like a 'method'"
0
 
mattisflonesAuthor Commented:
Oh for Fks sake... :-)

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

Thanks a million!
0
All Courses

From novice to tech pro — start learning today.