string FilePath = @"D:\Test\alllllllllthe Data.docx";
if (File.Exists(FilePath))
{
string FileContent = File.ReadAllText(FilePath);
}
答案 0 :(得分:0)
是的,我会诚实地说,不理解导致这种情况的变化,因为你是对的:
string filePath = @"D:\Folder\somefile.txt";
File.Exists(filePath) == TRUE // this is not happening
我更进了一步并做了:
try
{
var filePath = Path.GetFullPath("E:\\Folder\\somefile.txt");
File.OpenRead(filePath);
}
catch (Exception ex)
{ }
抛出的异常是:
NotSupportedException: The given path's format is not supported.
这确实有效,所以请试一试:
var filePath = Path.GetFullPath("D:\\Folder\\somefile.txt");
File.Exists(filePath) == TRUE // this does work
或者,您也可以使用它:
var path = @"D:\Folder";
var fileName = "somefile.txt";
var filePath = Path.Combine(path, fileName);
File.Exists(filePath) == TRUE // this does work