Search code examples
c#filepathfile-exists

Finding a xml config file


I am trying to check whether an xml config file exists.

The file has the name MyApp.exe.config

I am using

public static bool FileExistsCheck(string filename, string filepath = "")
{
    if (filepath.Length == 0)
        filepath = Directory.GetCurrentDirectory();
    return File.Exists(filepath + "\\" + filename);
}

this returns false despite the file existing

Can anyone advise on the correct way of checking whether or not this file exists?


Solution

  • try

    return File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)
    

    msdn