Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine appconfig contains a specific key [duplicate]

Tags:

c#

.net

Possible Duplicate:
C# assembly > app settings > how to check if one exists?

In the app.config, How can I know if it contains a specific key?

like image 802
user496949 Avatar asked Dec 23 '10 10:12

user496949


Video Answer


2 Answers

var specificValue = ConfigurationManager.AppSettings["specificKey"];
if (!string.IsNullOrEmpty(specificValue))
{
    // Use the value
}

but if you only want to check the presence you could also:

if (ConfigurationManager.AppSettings.AllKeys.Contains("specificKey"))
{
    // the config file contains the specific key    
}
like image 168
Darin Dimitrov Avatar answered Sep 27 '22 16:09

Darin Dimitrov


Try this:

if(ConfigurationManager.AppSettings["yourkey"] != null)
{
   // that key exists..... do something with it
}
like image 31
marc_s Avatar answered Sep 27 '22 18:09

marc_s