Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading values from app.config
Message
From
30/03/2013 14:04:59
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Reading values from app.config
Environment versions
Environment:
C# 4.0
Miscellaneous
Thread ID:
01569562
Message ID:
01569562
Views:
44
Hi,

this has to be really simple, but my searching is only turning up things that do not appear to work.

I have an app.config file with the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appsettings>
    <add key="Client" value="Data Source=MyServer; Initial Catalog=BPOpticalClient; Integrated Security=True"/>
    <add key="Server" value="Data Source=MyServer; Initial Catalog=BPOptical; Integrated Security=True"/>
  </appsettings>
</configuration>
How do I read the Client and Server values from this file?

If I try this:
string clientConnection = ConfigurationSettings.AppSettings["Client"];
I get a warning that this is obsolete and I should use:
System.Configuration!System.Configuration.ConfigurationManager.AppSettings
Using that gives me an error:

Other examples I've found give various errors.

Anyone have a simple example that will work for me?

update

I found a sample which worked:
string clientConnection = ConfigurationManager.AppSettings["Client"];
I don't know why this worked now as I had tried it before.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Next
Reply
Map
View

Click here to load this message in the networking platform