Solved

How to read a appSetting C#

Posted on 2006-10-26
4
2,264 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.
0
Comment
Question by:mattisflones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Pra4444
ID: 17814472
just try


String mailServerValue=ConfigurationSettings.AppSettings("mailServer")

similarly

String mailFromAddress=ConfigurationSettings.AppSettings("mailFromAddress")
0
 
LVL 15

Author Comment

by:mattisflones
ID: 17814817
Nope.. that makes .NET respond with:

"CS0118: 'System.Configuration.ConfigurationSettings.AppSettings' is a 'property' but is used like a 'method'"
0
 
LVL 12

Accepted Solution

by:
Pra4444 earned 500 total points
ID: 17814856
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
 
LVL 15

Author Comment

by:mattisflones
ID: 17814884
Oh for Fks sake... :-)

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

Thanks a million!
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question