Click or drag to resize

IHierarchyItemMoveToAsync Method

IT Hit WebDAV Classes Reference
Moves this item to the destination folder under a new name.

Namespace:  ITHit.WebDAV.Server
Assembly:  ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 13.3.13068
Syntax
Task MoveToAsync(
	IItemCollection destFolder,
	string destName,
	MultistatusException multistatus
)

Parameters

destFolder
Type: ITHit.WebDAV.ServerIItemCollection
Destination folder.
destName
Type: SystemString
Name of the destination item.
multistatus
Type: ITHit.WebDAV.ServerMultistatusException
If some items fail to copy but operation in whole shall be continued, add information about the error into multistatus using AddInnerException(String, DavException).

Return Value

Type: Task
.
Exceptions
ExceptionCondition
LockedExceptionThe source or the destination item was locked and client did not provide lock token.
NeedPrivilegesExceptionThe user doesn't have enough privileges.
InsufficientStorageExceptionQuota limit is reached.
MultistatusExceptionErrors has occured during processing of item in the subtree and whole operation shall be aborted.
DavExceptionIn other cases. Possible status value is CONFLICT if destination folder doesn't exist.
Remarks
If the item is locked the server must not move any locks with the item. However, items must be added to an existing lock at the destination.
Examples

The code below is part of 'WebDAVServer.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.

public override async Task MoveToAsync(IItemCollection destFolder, string destName, MultistatusException multistatus)
{
    await MoveToInternalAsync(destFolder, destName, multistatus, 0);
}

public override async Task MoveToInternalAsync(IItemCollection destFolder, string destName, MultistatusException multistatus, int recursionDepth)
{
    await RequireHasTokenAsync();

    DavFolder targetFolder = (DavFolder)destFolder;

    if (targetFolder == null || !Directory.Exists(targetFolder.FullPath))
    {
        throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT);
    }

    string newDirPath = System.IO.Path.Combine(targetFolder.FullPath, destName);
    string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName);
    // If an item with the same name exists in target directory - remove it.
    try
    {
        IHierarchyItem item = await context.GetHierarchyItemAsync(targetPath) as IHierarchyItem;

        if (item != null)
        {
            await item.DeleteAsync(multistatus);
        }
    }
    catch (DavException ex)
    {
        // Report exception to client and continue with other items by returning from recursion.
        multistatus.AddInnerException(targetPath, ex);
        return;
    }

    // Move the file.
    try
    {
        File.Move(fileSystemInfo.FullName, newDirPath);

        FileInfo newFileInfo = new FileInfo(newDirPath);
        if (FileSystemInfoExtension.IsUsingFileSystemAttribute)
        {
            await fileSystemInfo.MoveExtendedAttributes(newFileInfo);
        }

        // Locks should not be copied, delete them.
        if (await newFileInfo.HasExtendedAttributeAsync("Locks"))
            await newFileInfo.DeleteExtendedAttributeAsync("Locks");
    }
    catch (UnauthorizedAccessException)
    {
        // Exception occurred with the item for which MoveTo was called - fail the operation.
        NeedPrivilegesException ex = new NeedPrivilegesException("Not enough privileges");
        ex.AddRequiredPrivilege(targetPath, Privilege.Bind);

        string parentPath = System.IO.Path.GetDirectoryName(Path);
        ex.AddRequiredPrivilege(parentPath, Privilege.Unbind);
        throw ex;
    }
    if (recursionDepth == 0)
    {
        // Refresh client UI.
        await context.socketService.NotifyMovedAsync(Path, targetPath, GetWebSocketID());
    }
}

The code below is part of 'WebDAVServer.FileSystemSynchronization.AspNetCore' C# & VB samples provided with the SDK.

C#
public override async Task MoveToAsync(IItemCollection destFolder, string destName, MultistatusException multistatus)
{
    await MoveToInternalAsync(destFolder, destName, multistatus, 0);
}

public override async Task MoveToInternalAsync(IItemCollection destFolder, string destName, MultistatusException multistatus, int recursionDepth)
{
    await RequireHasTokenAsync();

    DavFolder targetFolder = (DavFolder)destFolder;

    if (targetFolder == null || !Directory.Exists(targetFolder.FullPath))
    {
        throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT);
    }

    string newDirPath = System.IO.Path.Combine(targetFolder.FullPath, destName);
    string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName);
    // Move the file.
    try
    {
        File.Move(fileSystemInfo.FullName, newDirPath, true);
        // Locks should not be copied, delete them.
        var newFileInfo = new FileInfo(newDirPath);
        if (await newFileInfo.HasExtendedAttributeAsync("Locks"))
            await newFileInfo.DeleteExtendedAttributeAsync("Locks");
    }
    catch (DavException ex)
    {
        // Report exception to client and continue with other items by returning from recursion.
        multistatus.AddInnerException(targetPath, ex);
        return;
    }
    catch (UnauthorizedAccessException)
    {
        // Exception occurred with the item for which MoveTo was called - fail the operation.
        NeedPrivilegesException ex = new NeedPrivilegesException("Not enough privileges");
        ex.AddRequiredPrivilege(targetPath, Privilege.Bind);

        string parentPath = System.IO.Path.GetDirectoryName(Path);
        ex.AddRequiredPrivilege(parentPath, Privilege.Unbind);
        throw ex;
    }
    if (recursionDepth == 0)
    {
        // Refresh client UI.
        await context.socketService.NotifyMovedAsync(Path, targetPath, GetWebSocketID());
    }
}
See Also