File.Copy then FIle.Delete IOError

    if (File.Exists(destFileName))
      {
        try
        {

          FileInfo fileInfo = new FileInfo(destFileName);
          System.Security.AccessControl.FileSecurity fileSecurity = fileInfo.GetAccessControl();
          fileSecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("Everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));

           fileSecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("Users", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));

          fileInfo.SetAccessControl(fileSecurity);

          fileInfo.Attributes = FileAttributes.Normal;//this is the real issue

          fileInfo.Delete();

          //File.Delete(destFileName);
        }
        catch (Exception ex)
        {

        }
      }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章