ConfigurationSettings.AppSettings is obsolete, warning

Sergio Tapia picture Sergio Tapia · Aug 10, 2010 · Viewed 19.2k times · Source
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?

Answer

Kelsey picture Kelsey · Aug 10, 2010

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.