{"record":{"id":"14c1e8ecad0ed3cd","repo":"OrchardCMS/OrchardCore","slug":"cannot-move-file-oldpath-to-newpath","errorCode":null,"errorMessage":"Cannot move file '{oldPath}' to '{newPath}'.","messagePattern":"Cannot move file '(.+?)' to '(.+?)'\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs","lineNumber":562,"sourceCode":"    }\n\n    public async Task MoveFileAsync(string oldPath, string newPath)\n    {\n        await EnsureCapabilitiesAsync();\n\n        if (_capabilities?.SupportsAtomicMove == true)\n        {\n            try\n            {\n                var oldFullPath = this.Combine(_basePrefix, oldPath);\n                var newFullPath = this.Combine(_basePrefix, newPath);\n\n                var fileClient = _dataLakeFileSystemClient.GetFileClient(oldFullPath);\n                await fileClient.RenameAsync(newFullPath);\n            }\n            catch (Exception ex)\n            {\n                throw new FileStoreException($\"Cannot move file '{oldPath}' to '{newPath}'.\", ex);\n            }\n\n            return;\n        }\n\n        try\n        {\n            await CopyFileAsync(oldPath, newPath);\n            await TryDeleteFileAsync(oldPath);\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot move file '{oldPath}' to '{newPath}'.\", ex);\n        }\n    }\n\n    public async Task CopyFileAsync(string srcPath, string dstPath)\n    {","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs#L544-L580","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the source file exists and the destination path (including parent directories) is valid before moving.","Check InnerException (RequestFailedException) for the concrete Azure error.","Create destination directories first or ensure the destination does not already exist.","Validate storage credentials and RBAC permissions."],"exampleFix":"// before\nawait _fileStore.MoveFileAsync(oldPath, newPath);\n// after\nif (await _fileStore.FileExistsAsync(oldPath) && !await _fileStore.FileExistsAsync(newPath))\n{\n    await _fileStore.MoveFileAsync(oldPath, newPath);\n}","handlingStrategy":"try-catch","validationCode":"if (!await _fileStore.FileExistsAsync(oldPath)) return;\nif (await _fileStore.FileExistsAsync(newPath)) return; // or delete/rename target first\nawait _fileStore.MoveFileAsync(oldPath, newPath);","typeGuard":null,"tryCatchPattern":"try\n{\n    await _fileStore.MoveFileAsync(oldPath, newPath);\n}\ncatch (FileStoreException ex)\n{\n    _logger.LogError(ex.InnerException, \"Move {Old} -> {New} failed\", oldPath, newPath);\n}","preventionTips":["Ensure destination parent directories exist before moving.","Treat the destination as create-if-absent; remove or rename conflicting targets first.","Use unique destination names under concurrency.","Validate credentials/RBAC on ADLS Gen2 accounts."],"tags":["azure-blob","file-storage","move-file"],"backgroundTag":"file-write-failed","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"}