Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading values from app.config
Message
De
30/03/2013 14:04:59
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Reading values from app.config
Versions des environnements
Environment:
C# 4.0
Divers
Thread ID:
01569562
Message ID:
01569562
Vues:
46
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform