Click or drag to resize

IFileSystemItemMoveToAsync Method

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

Namespace:  ITHit.FileSystem
Assembly:  ITHit.FileSystem (in ITHit.FileSystem.dll) Version: 3.1.7115.0-Beta
Syntax
Task MoveToAsync(
	string targetPath,
	IOperationContext operationContext,
	IConfirmationResultContext resultContext
)

Parameters

targetPath
Type: SystemString
Target path in the user file system.
operationContext
Type: ITHit.FileSystemIOperationContext
Provides information about the environment.
resultContext
Type: ITHit.FileSystemIConfirmationResultContext
Used to confirm the operation, report progress and status to the platform.

Return Value

Type: Task
.
Remarks

This method is called by the Engine when the file or a folder is being moved to a new location or renamed. In your method implementation you will either move the file or folder to a new location in your remote storage and confirm the operation or will just confirm the operation, while the acual move of the file/folder in the remote storage will be performed during your synchronization process.

Inside this method you will accept or reject the operation. To confirm the operation call the ReturnConfirmationResult method of the IConfirmationResultContext interface, passed via resultContext parameter. See IConfirmationResultContext interface description for details about confirming or rejecting the operation.

Examples

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

C#
public async Task MoveToAsync(string userFileSystemNewPath, IOperationContext operationContext, IConfirmationResultContext resultContext)
{
    string userFileSystemOldPath = this.UserFileSystemPath;
    Logger.LogMessage("IFileSystemItem.MoveToAsync()", userFileSystemOldPath, userFileSystemNewPath);

    // Process move.
    if (Engine.ChangesProcessingEnabled)
    {
        if (FsPath.Exists(userFileSystemOldPath))
        {
            await new RemoteStorageItem(userFileSystemOldPath).MoveToAsync(userFileSystemNewPath, resultContext);
            string remoteStorageOldPath = Mapping.MapPath(userFileSystemOldPath);
            string remoteStorageNewPath = Mapping.MapPath(userFileSystemNewPath);
            Logger.LogMessage("Moved succesefully", remoteStorageOldPath, remoteStorageNewPath);
        }
    }
    else
    {
        resultContext.ReturnConfirmationResult();
    }

    // Restore Original Path, if it's lost during MS Office transactional save.
    if (FsPath.Exists(userFileSystemNewPath) &&  PlaceholderItem.IsPlaceholder(userFileSystemNewPath))
    {
        PlaceholderItem userFileSystemNewItem = PlaceholderItem.GetItem(userFileSystemNewPath);
        if (!userFileSystemNewItem.IsNew() && string.IsNullOrEmpty(userFileSystemNewItem.GetOriginalPath()))
        {
            Logger.LogMessage("Saving Original Path", userFileSystemNewItem.Path);
            userFileSystemNewItem.SetOriginalPath(userFileSystemNewItem.Path);
        }
    }
}
C#
public async Task MoveToAsync(string userFileSystemNewPath, IOperationContext operationContext, IConfirmationResultContext resultContext)
{
    string userFileSystemOldPath = this.UserFileSystemPath;
    Logger.LogMessage("IFileSystemItem.MoveToAsync()", userFileSystemOldPath, userFileSystemNewPath);

    // Process move.
    if (Engine.ChangesProcessingEnabled)
    {
        if (FsPath.Exists(userFileSystemOldPath))
        {
            await new RemoteStorageRawItem(userFileSystemOldPath, Logger).MoveToAsync(userFileSystemNewPath, resultContext);
        }
    }
    else
    {
        resultContext.ReturnConfirmationResult();
    }

    // Restore Original Path and locked icon, lost during MS Office transactional save.
    if (FsPath.Exists(userFileSystemNewPath) &&  PlaceholderItem.IsPlaceholder(userFileSystemNewPath))
    {
        PlaceholderItem userFileSystemNewItem = PlaceholderItem.GetItem(userFileSystemNewPath);
        if (!userFileSystemNewItem.IsNew() && string.IsNullOrEmpty(userFileSystemNewItem.GetOriginalPath()))
        {
            // Restore Original Path.
            Logger.LogMessage("Saving Original Path", userFileSystemNewPath);
            userFileSystemNewItem.SetOriginalPath(userFileSystemNewPath);

            // Restore the 'locked' icon.
            bool isLocked = await Lock.IsLockedAsync(userFileSystemNewPath);
            await new UserFileSystemRawItem(userFileSystemNewPath).SetLockIconAsync(isLocked);
        }
    }
}
C#
public async Task MoveToAsync(string userFileSystemNewPath, IOperationContext operationContext, IConfirmationResultContext resultContext)
{
    string userFileSystemOldPath = this.UserFileSystemPath;
    Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(MoveToAsync)}()", userFileSystemOldPath, userFileSystemNewPath);

    string remoteStorageOldPath = RemoteStoragePath;
    string remoteStorageNewPath = Mapping.MapPath(userFileSystemNewPath);

    FileSystemInfo remoteStorageOldItem = FsPath.GetFileSystemItem(remoteStorageOldPath);
    if (remoteStorageOldItem != null)
    {
        if (remoteStorageOldItem is FileInfo)
        {
            (remoteStorageOldItem as FileInfo).MoveTo(remoteStorageNewPath, true);
        }
        else
        {
            (remoteStorageOldItem as DirectoryInfo).MoveTo(remoteStorageNewPath);
        }
        Logger.LogMessage("Moved item in remote storage succesefully", userFileSystemOldPath, userFileSystemNewPath);
    }
}
See Also