Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# file.Exists的正确语法(路径)_C#_Asp.net - Fatal编程技术网

C# file.Exists的正确语法(路径)

C# file.Exists的正确语法(路径),c#,asp.net,C#,Asp.net,在我的网站文件夹中有一个文件夹:讲师,在讲师文件夹中有许多子文件夹:讲师1、讲师2、讲师3……,子文件夹的名称是用户登录名(用户名) 它在每个讲师(n)文件夹中仍然有一个文件:profile.xml,但是isExists=false 尝试调试: username: lecturer1 path: "D:\\C#Projects\\website\\Lecturer\\" targetPath: "D:\\C#Projects\\website\\Lecturer\\lecturer1\\pro

在我的网站文件夹中有一个文件夹:
讲师
,在
讲师
文件夹中有许多子文件夹:
讲师1、讲师2、讲师3……
,子文件夹的名称是用户登录名(
用户名

它在每个
讲师(n)
文件夹中仍然有一个文件:
profile.xml
,但是
isExists=false

尝试调试:

username: lecturer1 
path: "D:\\C#Projects\\website\\Lecturer\\"
targetPath: "D:\\C#Projects\\website\\Lecturer\\lecturer1\\profile.xml"
但是
isExists:false。


帮助???我上面的代码有错误吗?

targetPath
是一个
文件
而不是目录,所以请使用
File.Exists
而不是
目录.Exists

bool isExists = System.IO.File.Exists(targetPath);

您是否尝试了没有尾部斜线的路径?另外,为什么要检查文件上是否存在目录?如果它不是一个directoryUse而不是字符串连接来构建路径,它就不存在了。哦,谢谢你,可怜的我,真不敢相信我没有意识到这一点。再次感谢^^
bool isExists = System.IO.File.Exists(targetPath);