OrchardCMS/OrchardCore · error · FileStoreException

Cannot move file ' ' because it does not exist.

Error message

Cannot move file '{oldPath}' because it does not exist.

What it means

MoveFileAsync validates the source before moving; if no file exists at oldPath it throws FileStoreException immediately instead of letting File.Move fail. The store gives an explicit, path-bearing message because a missing source is the most common move mistake.

Solutions

  1. Verify the source with await store.GetFileInfoAsync(oldPath) before moving.
  2. Correct the oldPath (check casing and extension).
  3. Use CopyFileAsync semantics or create the source file if it should exist.

Example fix

// before
await store.MoveFileAsync("uploads/old.txt", "uploads/new.txt"); // old.txt missing
// after
if (await store.GetFileInfoAsync("uploads/old.txt") is null)
    throw new InvalidOperationException("Source file missing before move");
await store.MoveFileAsync("uploads/old.txt", "uploads/new.txt");
Defensive patterns

Strategy: validation

Validate before calling

var src = await store.GetFileInfoAsync(oldPath);
if (src is null) throw new InvalidOperationException($"Source file '{oldPath}' does not exist");

Type guard

static async Task<bool> FileExistsAsync(IFileStore store, string path) => await store.GetFileInfoAsync(path) is not null;

Try / catch

try { await store.MoveFileAsync(oldPath, newPath); }
catch (FileStoreException ex) when (ex.Message.Contains("does not exist"))
{
    // handle missing source: log, skip, or recreate
}

Prevention

When it happens

Trigger: Calling MoveFileAsync(oldPath, newPath) where oldPath was never created, was already moved, was deleted, or the path is misspelled / wrong-cased.

Common situations: Renaming media items against a stale filename from a previous request; double-processing a workflow that moves a file then moves it again; typos in seeded content paths.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:251

            Directory.Delete(physicalPath, recursive: true);

            return Task.FromResult(true);
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot delete directory '{path}'.", ex);
        }
    }

    public Task MoveFileAsync(string oldPath, string newPath)
    {
        try
        {
            var physicalOldPath = GetPhysicalPath(oldPath);

            if (!File.Exists(physicalOldPath))
            {
                throw new FileStoreException($"Cannot move file '{oldPath}' because it does not exist.");
            }

            var physicalNewPath = GetPhysicalPath(newPath);

            if (File.Exists(physicalNewPath) || Directory.Exists(physicalNewPath))
            {
                throw new FileStoreException($"Cannot move file because the new path '{newPath}' already exists.");
            }

            File.Move(physicalOldPath, physicalNewPath);

            return Task.CompletedTask;
        }
        catch (FileStoreException)
        {
            throw;
        }
        catch (Exception ex)

View on GitHub (pinned to 4306c0717f)