Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does System.IO.File.Exists(string path) return false?

Tags:

c#

file

io

System.IO.File.Exists(string path) 

returns always false, even when the file exists on the specified path. What could be the possible solution?

like image 767
Shilpa Soni Avatar asked Aug 16 '13 05:08

Shilpa Soni


1 Answers

It could well be a permission problem. From the documentation:

The Exists method returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.

One way of seeing what's happening is to just try to read the file (e.g. with File.OpenRead). I'd be surprised if that succeeds - but if it fails, the exception should give you more information.

like image 167
Jon Skeet Avatar answered Sep 22 '22 16:09

Jon Skeet