A 3rd party library errors out when the file paths are invalid. We attempted to handle this case using File.Exists()
thinking that it would return false when the file path contains invalid characters, but it returns true.
This is strange (see the extra spaces and period)
string wrong = "myfolder1\\myfolder2\\myfile.txt .";
bool x = File.Exists(wrong);
Is there a way to clean up the file path?
new FileInfo(wrong).Name
does not clean it up.
Our main purpose is to reliably determine if the file path is valid before sending it into the 3rd party library. I almost feel stupid asking this question because I think that File.Exists() ought to be doing this.
(We're on .NET 4.0)