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?
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
}
Try this:
if(ConfigurationManager.AppSettings["yourkey"] != null)
{
// that key exists..... do something with it
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With