How to retrieve appsetings in WinForm Application?

A

ad

I have define some appsetings in ap.config like:

<configuration>
<appSettings>
<add key="MailBody" value="Test Mail body"/>
</appSettings>

.....

I use
txtSubject.Text =
ConfigurationManager.AppSettings["MailSubject"].ToString();

But it can't compile.

How can I retrieve appsetings in WinForm applicaiton
 
L

Lars Behrmann

Hi,

you should use

System.Configuration.ConfigurationSettings.AppSettings["MailBody"];

You should better read the value into a string first
and after you check that it isn't null set it where
you need it.

Cheers
Lars Behrmann

_________________
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/
 
J

Jon Skeet [C# MVP]

ad said:
I have define some appsetings in ap.config like:

<configuration>
<appSettings>
<add key="MailBody" value="Test Mail body"/>
</appSettings>

....

I use
txtSubject.Text =
ConfigurationManager.AppSettings["MailSubject"].ToString();

But it can't compile.

How can I retrieve appsetings in WinForm applicaiton

It should be ConfigurationSettings.AppSettings, not
ConfigurationManager.AppSettings.
 
A

ad

I am using VS2005, it say that the ConfigurationSettings is obsoleted.



Jon Skeet said:
ad said:
I have define some appsetings in ap.config like:

<configuration>
<appSettings>
<add key="MailBody" value="Test Mail body"/>
</appSettings>

....

I use
txtSubject.Text =
ConfigurationManager.AppSettings["MailSubject"].ToString();

But it can't compile.

How can I retrieve appsetings in WinForm applicaiton

It should be ConfigurationSettings.AppSettings, not
ConfigurationManager.AppSettings.
 
F

Frank Dzaebel

Hello ad,
I have define some appsetings in ap.config like:
<configuration> <appSettings> <add key="MailBody"
value="Test Mail body"/> </appSettings> </configuration>
I use: txtSubject.Text =
ConfigurationManager.AppSettings["MailSubject"].ToString();
But it can't compile.
How can I retrieve appsetings in WinForm applicaiton

Thats ok, if you use .NET Framework 2.0, so

// insert reference to system.configuration.dll [2.0]
// using System.Configuration.
string s = ConfigurationManager.AppSettings["MailBody"];


ciao Frank
 
J

Jon Skeet [C# MVP]

ad said:
I am using VS2005, it say that the ConfigurationSettings is obsoleted.

Ah. It would have helped if you'd said that to start with...

ConfigurationManager should be fine then. Here's a sample program that
works:

using System;
using System.Configuration;

public class Test
{
static void Main()
{
Console.WriteLine (ConfigurationManager.AppSettings["Foo"]);
}
}

Test.exe.config:
<?xml version="1.0" ?>
<configuration>
<appSettings>
<add key="Foo" value="Bar" />
</appSettings>
</configuration>

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top