简体   繁体   English

调用 Directory.Move(..., ...) 时访问路径被拒绝异常

[英]Access to the path is denied exception when calling Directory.Move(..., ...)

Directory.Move("source","Des")

This code throws the following exception:此代码抛出以下异常:

System.UnauthorizedAccessException: Access to the path is denied. ---> System.IO.IOException: Operation not permitted

Run the application as a user who has access to the directory (like administrator or Windows Service), Or in case you just want to know if the application is running well give access to the user or "everyone" to the directory.以有权访问目录的用户身份运行应用程序(如管理员或 Windows 服务),或者如果您只想知道应用程序是否运行良好,请授予用户或“所有人”访问目录的权限。

you can give access to the user via CMD (run as administrator)您可以通过CMD授予用户访问权限(以管理员身份运行)

C:\>icacls "D:\test" /grant everyone:(OI)(CI)F /T

According do MS documentation:根据 MS 文档:

F = Full Control F = 完全控制

CI = Container Inherit - This flag indicates that subordinate containers will inherit this ACE. CI = Container Inherit - 此标志表示从属容器将继承此 ACE。

OI = Object Inherit - This flag indicates that subordinate files will inherit the ACE. OI = Object Inherit - 此标志表示从属文件将继承 ACE。

/T = Apply recursively to existing files and sub-folders. /T = 递归地应用于现有文件和子文件夹。 (OI and CI only apply to new files and sub-folders). (OI 和 CI 仅适用于新文件和子文件夹)。

For complete documentation, you may run "icacls" with no arguments or see the Microsoft documentation here and here要获得完整的文档,您可以在没有 arguments 的情况下运行“icacls”,或者在此处和此处查看 Microsoft 文档

check this answer as well on giving permissions: https://stackoverflow.com/a/8311008/3563665在授予权限时还要检查此答案: https://stackoverflow.com/a/8311008/3563665

Directory.Move("source","Des")

This code throws the following exception:此代码引发以下异常:

System.UnauthorizedAccessException: Access to the path is denied. ---> System.IO.IOException: Operation not permitted

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

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