Namespace: ITHit.WebDAV.Server
void CopyTo( 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 CopyTo 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.NtfsStorage' sample provided with the SDK.
public override void CopyTo(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus) { context.FileOperation( () => copyToInternal(destFolder, destName, multistatus)); } private void copyToInternal(IItemCollection folder, string destName, MultistatusException multistatus) { var targetFolder = (DavFolder)folder; if (targetFolder == null || !Directory.Exists(targetFolder.GetFullPath())) { throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT); } var newDirPath = System.IO.Path.Combine(targetFolder.GetFullPath(), destName); var targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); //If an item with the same name exists - remove it. try { IHierarchyItem item = context.GetHierarchyItem(targetPath); if (item != null) item.Delete(multistatus); } catch (DavException ex) { //Report error with other item to client. multistatus.AddInnerException(targetPath, ex); return; } //Copy the file. try { File.Copy(fileSystemInfo.FullName, newDirPath); DeleteStream(newDirPath, "Locks"); } catch (UnauthorizedAccessException) { //Fail var ex = new NeedPrivilegesException("Not enough privileges"); string parentPath = System.IO.Path.GetDirectoryName(Path); ex.AddRequiredPrivilege(parentPath, Privilege.Bind); throw ex; } }