Solved

How to read a appSetting C#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating a flowchart from an algorithm 5 30
Asp.net mvc 5 5 43
Please explain "Multi-Tenant Services" 5 60
.NET tools for adding thread safety to a web app? 3 6
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now