ConfigurationSettings.AppSettings is obsolete, warning

后端 未结 4 466
眼角桃花
眼角桃花 2021-01-03 00:51
var values = new NameValueCollection
{
    { \"key\", ConfigurationSettings.AppSettings[\"API-Key\"].ToString() },
    { \"image\", Convert.ToBase64String(File.ReadA         


        
相关标签:
4条回答
  • 2021-01-03 01:26

    With the ConfigurationManager class

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

    0 讨论(0)
  • 2021-01-03 01:40

    The new class to use is the ConfigurationManager class.

    0 讨论(0)
  • 2021-01-03 01:43

    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.

    0 讨论(0)
  • 2021-01-03 01:45

    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.

    0 讨论(0)
提交回复
热议问题