简体   繁体   English

Directory.Exists 在目录存在时返回 false(适用于独立控制台应用程序,但不适用于 ASP 项目)

[英]Directory.Exists returns false when directory is present (works in a standalone console application but not in an ASP project)

As it is described in the title, ASP.NET project code can't find the directory, which exists and can be found by the console C# application.如标题所述,ASP.NET 项目代码找不到该目录,该目录存在,可以通过控制台 C# 应用程序找到。 (Disclaimer: I am totally new to .NET and C#). (免责声明:我对 .NET 和 C# 完全陌生)。

This displays "true" in the console application, but Directory.Exists evaluates to false in the ASP.NET application.这在控制台应用程序中显示“真”,但在 ASP.NET 应用程序中, Directory.Exists的计算结果为假。

string directoryPath = 
                "C:\\Users\\AndreasT\\ProjectDirectory\\ChildDirectory";

Console.WriteLine(Directory.Exists(directoryPath));

As I am new to .NET, I cannot give more detailed and accurate information at the moment, so I am looking for any suggestions of what could be wrong (permissions, project setup, etc.)由于我是 .NET 的新手,目前我无法提供更详细和准确的信息,因此我正在寻找任何可能出现问题的建议(权限、项目设置等)

Directory.Exists() method returns false if you dont have minimum read-only permission.如果您没有最低只读权限, Directory.Exists()方法将返回false It returns false in the following conditions.它在以下情况下返回false

  1. File name with invalid characters包含无效字符的文件名
  2. Too many characters字符太多
  3. Failing or missing disk磁盘故障或丢失
  4. No permission to read the file没有读取文件的权限

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.exists?view=netcore-3.1#remarks参考: https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.exists?view=netcore-3.1#remarks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM