OrchardCMS/OrchardCore · error · FileStoreException

Cannot move file ' ' to ' '.

Error message

Cannot move file '{oldPath}' to '{newPath}'.

What it means

Thrown by MoveFileAsync when the file rename fails on accounts with a hierarchical namespace (ADLS Gen2), where a move is implemented as a Data Lake RenameAsync. The original exception is preserved as InnerException with both paths in the message.

Solutions

  1. Verify the source file exists and the destination path (including parent directories) is valid before moving.
  2. Check InnerException (RequestFailedException) for the concrete Azure error.
  3. Create destination directories first or ensure the destination does not already exist.
  4. Validate storage credentials and RBAC permissions.

Example fix

// before
await _fileStore.MoveFileAsync(oldPath, newPath);
// after
if (await _fileStore.FileExistsAsync(oldPath) && !await _fileStore.FileExistsAsync(newPath))
{
    await _fileStore.MoveFileAsync(oldPath, newPath);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!await _fileStore.FileExistsAsync(oldPath)) return;
if (await _fileStore.FileExistsAsync(newPath)) return; // or delete/rename target first
await _fileStore.MoveFileAsync(oldPath, newPath);

Try / catch

try
{
    await _fileStore.MoveFileAsync(oldPath, newPath);
}
catch (FileStoreException ex)
{
    _logger.LogError(ex.InnerException, "Move {Old} -> {New} failed", oldPath, newPath);
}

Prevention

When it happens

Trigger: Calling IFileStore.MoveFileAsync(oldPath, newPath) when RenameAsync fails: source file does not exist, destination parent directory does not exist, destination already exists, or permission/network errors.

Common situations: Media module moving assets into a folder that was never created on ADLS; race where another process already created the destination; expired SAS/keys; 403 from missing RBAC role.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/14c1e8ecad0ed3cd. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs:562

    }

    public async Task MoveFileAsync(string oldPath, string newPath)
    {
        await EnsureCapabilitiesAsync();

        if (_capabilities?.SupportsAtomicMove == true)
        {
            try
            {
                var oldFullPath = this.Combine(_basePrefix, oldPath);
                var newFullPath = this.Combine(_basePrefix, newPath);

                var fileClient = _dataLakeFileSystemClient.GetFileClient(oldFullPath);
                await fileClient.RenameAsync(newFullPath);
            }
            catch (Exception ex)
            {
                throw new FileStoreException($"Cannot move file '{oldPath}' to '{newPath}'.", ex);
            }

            return;
        }

        try
        {
            await CopyFileAsync(oldPath, newPath);
            await TryDeleteFileAsync(oldPath);
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot move file '{oldPath}' to '{newPath}'.", ex);
        }
    }

    public async Task CopyFileAsync(string srcPath, string dstPath)
    {

View on GitHub (pinned to 4306c0717f)