Athiwat Chunlakhan
Athiwat Chunlakhan

Reputation: 7809

File Exists in WPF

if (!File.Exists("SomeFile.exe"))
{
//Does not exists
}

I have SomeFile.exe in the same path as the exe but the result is Does not Exists.

This does not happen in Windows Form, does something change?

Upvotes: 6

Views: 18293

Answers (2)

Patrik Svensson
Patrik Svensson

Reputation: 13874

Try this to get the file in the executables directory.

string directory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string filePath = Path.Combine(directory, "SomeFile.exe");

if (!File.Exists(filePath))
{
    // 1337 code here plx.
}

Upvotes: 10

RvdK
RvdK

Reputation: 19800

If your testing it from VS then the current directory is the Project dir not the release/debug folder (where your exe is)

Upvotes: 2

Related Questions