IHierarchyItem.CopyTo Method 

IT Hit WebDAV for .NET

Creates a copy of this item with a new name in the destination folder.

[Visual Basic]
Function CopyTo( _
   ByVal folder As IFolder, _
   ByVal destName As String, _
   ByVal deep As Boolean _
) As WebDAVResponse
[C#]
WebDAVResponse CopyTo(
   IFolder folder,
   string destName,
   bool deep
);

Parameters

folder
Destination folder.
destName
Name of the destination item.
deep
Indicates whether to copy entire subtree.

Return Value

Remarks

If error occurred while copying resource located in a subtree, the server should try to continue copy operation and copy all other items. In this case you must return MultistatusResponse that contain separate ItemResponse for every item that was successfully copied or failed to copy.

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.

Example

Example of CopyTo implementation for WebDAV Class 2 server:

 public class Folder : HierarchyItem, IFolder, IFolderLock
 {
        ...
        public override WebDAVResponse CopyTo(IFolder folder, string destName, bool deep)
        {
            Folder destFolder = folder as Folder;
            if(destFolder == null)
                return new ConflictResponse();
            if(!destFolder.ClientHasToken)
                return new LockedResponse();

            IHierarchyItem destItem = destFolder.FindChild(destName);
            Folder newDestFolder;
            
            if(destItem != null)
            {
                if(destItem is IResource)
                {
                    WebDAVResponse delResp = destItem.Delete();
                    if(!delResp.IsSuccess)
                        return delResp;
                    newDestFolder = CopyThisItem(destFolder, null, destName);
                }
                else
                {
                    newDestFolder = destItem as Folder;
                    if(newDestFolder == null)
                        return new ConflictResponse();
                }
            }
            else
            {
                newDestFolder = CopyThisItem(destFolder,null,destName);
            }
            // copy children
            MultistatusResponse mr = new MultistatusResponse();
            if(deep)
            {
                foreach(IHierarchyItem child in Children)
                {
                    HierarchyItem dbchild = child as HierarchyItem;
                    WebDAVResponse resp = dbchild.CopyTo(newDestFolder,child.Name,deep);
                    if(!resp.IsSuccess)
                        mr.AddResponses(new ItemResponse(dbchild.Path, resp));
                    else
                    {
                        MultistatusResponse mrchild = resp as MultistatusResponse;
                        if(mrchild != null)
                            mr.AddResponses(mrchild.Responses);
                    }
                }
            }

            if(mr.Responses.Length > 0)
                return mr;
            else if(destItem == null)
                return new CreatedResponse();
            else
                return new NoContentResponse();
        }
        ...
    }
 

See Also

IHierarchyItem Interface | ITHit.WebDAV.Server Namespace