Solved

How to read a appSetting C#

Posted on 2006-10-26
4
2,256 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
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert value of checklistbox checked 4 38
TimeZone, day light savings, Sql server, asp.net 6 38
asp Google Map 2 55
Header Font Size in Grid View 6 22
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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