Sergio Tapia
Sergio Tapia

Reputation: 41138

ConfigurationSettings.AppSettings is obsolete, warning

var values = new NameValueCollection
{
    { "key", ConfigurationSettings.AppSettings["API-Key"].ToString() },
    { "image", Convert.ToBase64String(File.ReadAllBytes(photo.ToString())) }
};

What's the new way to use the app.config file?

Upvotes: 6

Views: 20700

Answers (4)

David
David

Reputation: 73564

Use the System.Configuration.ConfigurationManager class

string ServerName = System.Configuration.ConfigurationManager.AppSettings["Servername"];

Edit - added

Note, you may have to add a reference to System.Configuration.dll. Even if you can import the namespace without the reference, you will not be able to access this class unless you have the reference.

Upvotes: 7

Kelsey
Kelsey

Reputation: 47726

The ConfigurationManager class in System.Configuration:

ConfigurationManager.AppSettings

ConfigurationManager.ConnectionStrings

So your code would change to:

var values = new NameValueCollection 
{ 
    { "key", ConfigurationManager.AppSettings["API-Key"] }, 
    { "image", Convert.ToBase64String(File.ReadAllBytes(photo.ToString())) } 
}; 

Make sure you add a reference to System.Configuration along with the using statement for System.Configuration.

Upvotes: 18

Adam V
Adam V

Reputation: 6356

The new class to use is the ConfigurationManager class.

Upvotes: 2

Eton B.
Eton B.

Reputation: 6281

With the ConfigurationManager class

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

Upvotes: 3

Related Questions