{"record":{"id":"72683008a110b430","repo":"OrchardCMS/OrchardCore","slug":"cannot-move-file-oldpath-because-it-does-not-exist","errorCode":null,"errorMessage":"Cannot move file '{oldPath}' because it does not exist.","messagePattern":"Cannot move file '(.+?)' because it does not exist\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs","lineNumber":251,"sourceCode":"            Directory.Delete(physicalPath, recursive: true);\n\n            return Task.FromResult(true);\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot delete directory '{path}'.\", ex);\n        }\n    }\n\n    public Task MoveFileAsync(string oldPath, string newPath)\n    {\n        try\n        {\n            var physicalOldPath = GetPhysicalPath(oldPath);\n\n            if (!File.Exists(physicalOldPath))\n            {\n                throw new FileStoreException($\"Cannot move file '{oldPath}' because it does not exist.\");\n            }\n\n            var physicalNewPath = GetPhysicalPath(newPath);\n\n            if (File.Exists(physicalNewPath) || Directory.Exists(physicalNewPath))\n            {\n                throw new FileStoreException($\"Cannot move file because the new path '{newPath}' already exists.\");\n            }\n\n            File.Move(physicalOldPath, physicalNewPath);\n\n            return Task.CompletedTask;\n        }\n        catch (FileStoreException)\n        {\n            throw;\n        }\n        catch (Exception ex)","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs#L233-L269","documentation":"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.","triggerScenarios":"Calling MoveFileAsync(oldPath, newPath) where oldPath was never created, was already moved, was deleted, or the path is misspelled / wrong-cased.","commonSituations":"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.","solutions":["Verify the source with await store.GetFileInfoAsync(oldPath) before moving.","Correct the oldPath (check casing and extension).","Use CopyFileAsync semantics or create the source file if it should exist."],"exampleFix":"// before\nawait store.MoveFileAsync(\"uploads/old.txt\", \"uploads/new.txt\"); // old.txt missing\n// after\nif (await store.GetFileInfoAsync(\"uploads/old.txt\") is null)\n    throw new InvalidOperationException(\"Source file missing before move\");\nawait store.MoveFileAsync(\"uploads/old.txt\", \"uploads/new.txt\");","handlingStrategy":"validation","validationCode":"var src = await store.GetFileInfoAsync(oldPath);\nif (src is null) throw new InvalidOperationException($\"Source file '{oldPath}' does not exist\");","typeGuard":"static async Task<bool> FileExistsAsync(IFileStore store, string path) => await store.GetFileInfoAsync(path) is not null;","tryCatchPattern":"try { await store.MoveFileAsync(oldPath, newPath); }\ncatch (FileStoreException ex) when (ex.Message.Contains(\"does not exist\"))\n{\n    // handle missing source: log, skip, or recreate\n}","preventionTips":["Always verify the source exists before moving.","Track moved files to avoid double-move logic in workflows.","Store canonical paths (correct casing) so lookups match."],"tags":["filesystem","file-store","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}