Namespace: ITHit.WebDAV.Server
Task CopyToAsync( IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus )
Exception | Condition |
---|---|
LockedException | Destination item was locked and client did not provide lock token. |
NeedPrivilegesException | The user doesn't have enough privileges. |
InsufficientStorageException | Quota limit is reached. |
MultistatusException | Errors has occured during processing of item in the subtree and whole operation shall be aborted. |
DavException | In other cases. Possible status value is CONFLICT if destination folder doesn't exist. |
If error occurred while copying file located in a subtree, the server should try to continue copy operation and copy all other items. In this case you must add that error multistatus container.
A CopyToAsync method invocation must not copy any locks active on the source item. However, if this method copies the item into a folder that has a deep lock, then the destination item must be added to the lock.
The code below is part of 'WebDAVServer.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.
public override async Task CopyToAsync(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus) { await CopyToInternalAsync(destFolder, destName, deep, multistatus, 0); } public override async Task CopyToInternalAsync(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus, int recursionDepth) { DavFolder targetFolder = (DavFolder)destFolder; if (targetFolder == null || !Directory.Exists(targetFolder.FullPath)) { throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT); } string newFilePath = System.IO.Path.Combine(targetFolder.FullPath, destName); string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); // If an item with the same name exists - remove it. try { IHierarchyItem item = await context.GetHierarchyItemAsync(targetPath); if (item != null) await item.DeleteAsync(multistatus); } catch (DavException ex) { // Report error with other item to client. multistatus.AddInnerException(targetPath, ex); return; } // Copy the file togather with all extended attributes (custom props and locks). try { File.Copy(fileSystemInfo.FullName, newFilePath); var newFileSystemInfo = new FileInfo(newFilePath); if (FileSystemInfoExtension.IsUsingFileSystemAttribute) { await fileSystemInfo.CopyExtendedAttributes(newFileSystemInfo); } // Locks should not be copied, delete them. if (await fileSystemInfo.HasExtendedAttributeAsync("Locks")) { await newFileSystemInfo.DeleteExtendedAttributeAsync("Locks"); } } catch (UnauthorizedAccessException) { // Fail NeedPrivilegesException ex = new NeedPrivilegesException("Not enough privileges"); string parentPath = System.IO.Path.GetDirectoryName(Path); ex.AddRequiredPrivilege(parentPath, Privilege.Bind); throw ex; } if (recursionDepth == 0) { await context.socketService.NotifyCreatedAsync(targetPath, GetWebSocketID()); } }
The code below is part of 'WebDAVServer.FileSystemSynchronization.AspNetCore' C# & VB samples provided with the SDK.
public override async Task CopyToAsync(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus) { await CopyToInternalAsync(destFolder, destName, deep, multistatus, 0); } public override async Task CopyToInternalAsync(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus, int recursionDepth) { DavFolder targetFolder = (DavFolder)destFolder; if (targetFolder == null || !Directory.Exists(targetFolder.FullPath)) { throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT); } string newFilePath = System.IO.Path.Combine(targetFolder.FullPath, destName); string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); // Copy the file togather with all extended attributes (custom props and locks). try { File.Copy(fileSystemInfo.FullName, newFilePath, true); // Locks should not be copied, delete them. if (await fileSystemInfo.HasExtendedAttributeAsync("Locks")) await new FileInfo(newFilePath).DeleteExtendedAttributeAsync("Locks"); } catch (DavException ex) { // Report error with other item to client. multistatus.AddInnerException(targetPath, ex); return; } catch (UnauthorizedAccessException) { // Fail NeedPrivilegesException ex = new NeedPrivilegesException("Not enough privileges"); string parentPath = System.IO.Path.GetDirectoryName(Path); ex.AddRequiredPrivilege(parentPath, Privilege.Bind); throw ex; } if (recursionDepth == 0) { await context.socketService.NotifyCreatedAsync(targetPath, GetWebSocketID()); } }