Click or drag to resize

IFileSystemItemMoveToAsync Method

IT Hit User File System
Called before a file or a folder is moved to a new location or renamed.

Namespace:  ITHit.FileSystem
Assembly:  ITHit.FileSystem (in ITHit.FileSystem.dll) Version: 8.3.27213.0
Syntax
Task MoveToAsync(
	string targetUserFileSystemPath,
	byte[] targetFolderRemoteStorageItemId,
	IOperationContext operationContext,
	IConfirmationResultContext resultContext,
	CancellationToken cancellationToken = null
)

Parameters

targetUserFileSystemPath
Type: SystemString
Target path in the user file system.
targetFolderRemoteStorageItemId
Type: SystemByte
New parent item ID or null if the item ID was never set. This parameter can also be null if the target folder is not a placeholder (for example a new folder).
operationContext
Type: ITHit.FileSystemIOperationContext
Provides information about the environment. On Windows platform this parameter can be be casted to [!:ITHit.FileSystem.Windows.IMoveContext] to extract source and target item path.
resultContext
Type: ITHit.FileSystemIConfirmationResultContext
Used to confirm the operation, report progress and status to the platform.
cancellationToken (Optional)
Type: System.ThreadingCancellationToken
The token to monitor for cancellation requests.

Return Value

Type: Task
A task object that can be awaited.
Remarks

This method is called before a file or a folder is being moved to a new location or renamed.

Inside this method you can accept or reject the operation. To confirm the operation call the ReturnConfirmationResult method of the IConfirmationResultContext interface, passed via the resultContext parameter. To reject the operation call the ReturnErrorResult(CloudFileStatus) method or throw any exception. If no exception is thrown, the operation is confirmed automatically.

Note that this method is called only when the Engine is running. If the item is being moved when the Engine was stopped, only the [!:MoveToCompletionAsync] method is called when the Engine is started and the [!:OutgoingSync.ProcessAsync] method is called.

Examples

The code below is part of 'VirtualFileSystem' C# sample provided with the SDK.

C#
public async Task MoveToAsync(string targetUserFileSystemPath, byte[] targetFolderRemoteStorageItemId, IOperationContext operationContext, IConfirmationResultContext resultContext, CancellationToken cancellationToken = default)
{
    IWindowsMoveContext moveContext = operationContext as IWindowsMoveContext;
    string userFileSystemNewPath = moveContext.TargetPath;
    string userFileSystemOldPath = this.UserFileSystemPath;
    Logger.LogDebug($"{nameof(IFileSystemItem)}.{nameof(MoveToAsync)}()", userFileSystemOldPath, userFileSystemNewPath, moveContext);
}

public async Task MoveToCompletionAsync(string targetUserFileSystemPath, byte[] targetFolderRemoteStorageItemId, IWindowsMoveContext moveContext, IInSyncStatusResultContext resultContext, CancellationToken cancellationToken = default)
{
    string userFileSystemNewPath = moveContext.TargetPath; 
    string userFileSystemOldPath = this.UserFileSystemPath;
    Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(MoveToCompletionAsync)}()", userFileSystemOldPath, userFileSystemNewPath, moveContext);

    FileSystemInfo remoteStorageOldItem = FsPath.GetFileSystemItem(RemoteStoragePath);

    if (remoteStorageOldItem != null)
    {
        string remoteStorageNewPath = mapping.MapPath(userFileSystemNewPath);
        if (remoteStorageOldItem is FileInfo)
        {
            if (File.Exists(remoteStorageNewPath))
            {
                File.Delete(remoteStorageNewPath);
            }
            (remoteStorageOldItem as FileInfo).MoveTo(remoteStorageNewPath);
        }
        else
        {
            (remoteStorageOldItem as DirectoryInfo).MoveTo(remoteStorageNewPath);
        }

        Logger.LogDebug("Moved in the remote storage successfully", userFileSystemOldPath, userFileSystemNewPath, moveContext);
    }
}
See Also