简体   繁体   English

使用C#拒绝访问路径来移动目录

[英]Access to path is denied moving a directory using c#

When I tried to cut and paste the directory (subfolder and files) it gives me error access to the path is denied. 当我尝试剪切和粘贴目录(子文件夹和文件)时,它给我错误访问路径的权限被拒绝。 Sometime it works when I upload any files to that directory then it shows error. 有时,当我将任何文件上传到该目录时,它都起作用,然后显示错误。

I have full access to that directory and subdirectories. 我拥有对该目录和子目录的完全访问权限。 I am able to delete and upload files under that directory, but cannot move that Directory to any other location. 我可以删除和上传该目录下的文件,但是不能将该目录移动到任何其他位置。

I have tried: 我努力了:

  1. Full Access to network service and Everyone. 完全访问网络服务和所有人。
  2. Update identity of application pool. 更新应用程序池的标识。

I have also tried this 我也尝试过

 DirectorySecurity dSecurity = dInfo.GetAccessControl();
 dSecurity.AddAccessRule(
    new FileSystemAccessRule("everyone", FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,PropagationFlags.InheritOnly,AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);

 //move function
 Source = Server. MapPath (source);
  destination = Server.MapPath(destination);  
  If (! Directory. Exists (destination))
   {                           
    Directory.Move(source, destination);                              

   }
   catch (Exception e)
  {
      return e.Message;
  }

If you have any idea why I am getting this error please let me know. 如果您知道为什么我会收到此错误,请告诉我。

It is possible that one of the files in the "source" directory is in use and cannot be moved. “源”目录中的文件之一可能正在使用中,无法移动。 Try moving each file in the directory one by one in a loop. 尝试循环循环移动目录中的每个文件。

as @Arsen said try to move each file one by one,, 正如@Arsen所说,尝试将每个文件一一移动,

Also check for 同时检查

**Mode of the directory **目录模式

**Permission of user who try to move the directory **尝试移动目录的用户的权限

**else, probably try to move the directory as a superuser. **否则,可能尝试以超级用户身份移动目录。

It is possible that one of the files in the source directory is using by another process and can not moved. 源目录中的一个文件可能正在被另一个进程使用,并且无法移动。 Try to moving each file one by one then you get some files is in use by another process. 尝试逐个移动每个文件,然后您会发现某些文件正在被另一个进程使用。

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

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