Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to determine whether app.config file exists

Tags:

c#

app-config

Is there a way to find out whether an app.config file exists, without using "File.Exists"? I tried

if ( !ConfigurationManager.ConnectionStrings.ElementInformation.IsPresent )
{...}

but IsPresent is false even if app.config with a connection string exists.

Edit: Did I misinterpret the IsPresent Property?

like image 916
ibram Avatar asked Mar 14 '11 10:03

ibram


1 Answers

The AppDomain reports on where it expects the configuration file for the application to reside. You can test if the file actually exists (with no need for dummy AppSettings, and no need to try and work out what the configuration file should be called, or where it is located):

public static bool CheckConfigFileIsPresent()
{
   return File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
}
like image 154
Rob Levine Avatar answered Nov 03 '22 15:11

Rob Levine