{"record":{"id":"8b0e371aca1630e5","repo":"OrchardCMS/OrchardCore","slug":"cannot-create-file-path-filesystemstore","errorCode":null,"errorMessage":"Cannot create file '{path}'.","messagePattern":"Cannot create file '(.+?)'\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs","lineNumber":388,"sourceCode":"            }\n\n            // Create directory path if it doesn't exist.\n            var physicalDirectoryPath = Path.GetDirectoryName(physicalPath);\n            Directory.CreateDirectory(physicalDirectoryPath);\n\n            var fileInfo = new FileInfo(physicalPath);\n            await using var outputStream = fileInfo.Create();\n            await inputStream.CopyToAsync(outputStream);\n\n            return path;\n        }\n        catch (FileStoreException)\n        {\n            throw;\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot create file '{path}'.\", ex);\n        }\n    }\n\n    public Task<long?> GetPermittedStorageAsync()\n    {\n        try\n        {\n            var path = GetPhysicalPath(null);\n            var driveOfStoreRoot = DriveInfo\n                .GetDrives()\n                .OrderByDescending(drive => drive.Name.Length)\n                .FirstOrDefault(drive => path.StartsWith(drive.Name));\n\n            return Task.FromResult(driveOfStoreRoot?.AvailableFreeSpace);\n        }\n        catch (Exception ex)\n        {\n            // It is possible, that the process only has limited access to the drive and trying to get this information","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs#L370-L406","documentation":"This is the generic catch-all in FileSystemStore.CreateFileFromStreamAsync: any exception that is not a FileStoreException (e.g. IOException from disk full, UnauthorizedAccessException, DirectoryNotFoundException, path-format errors) is re-wrapped in a FileStoreException with the message 'Cannot create file'. The original exception is preserved as InnerException.","triggerScenarios":"Calling IFileStore.CreateFileFromStreamAsync(path, stream) when the underlying write fails for an environmental reason: no write permission on the target directory, disk full, path too long, invalid path characters, or the directory was deleted between creation and the write.","commonSituations":"Read-only app_data volume or container filesystem; insufficient ACLs for the app pool identity; long paths (>260 chars) on Windows without long-path support; media module writes failing after a volume remount; antivirus locking the target file.","solutions":["Inspect the InnerException of the thrown FileStoreException to identify the real cause (IOException, UnauthorizedAccessException, etc.).","Verify the app identity has write permission on the store root (App_Data or the configured media root).","Check available disk space and remove path-length/invalid-character issues in the supplied path.","If transient (locked file, network volume), wait and retry the operation.","Log the original exception rather than only the outer message."],"exampleFix":"// before\nawait fileStore.CreateFileFromStreamAsync(path, stream);\n// after\ntry\n{\n    await fileStore.CreateFileFromStreamAsync(path, stream);\n}\ncatch (FileStoreException ex)\n{\n    logger.LogError(ex.InnerException, \"Failed to create file '{Path}': {Reason}\", path, ex.InnerException?.Message);\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"if (!Directory.Exists(Path.GetDirectoryName(physicalPath)))\n{\n    throw new InvalidOperationException(\"Target directory does not exist or is not writable.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await fileStore.CreateFileFromStreamAsync(path, stream);\n}\ncatch (FileStoreException ex)\n{\n    logger.LogError(ex.InnerException ?? ex, \"CreateFileFromStreamAsync failed for '{Path}'\", path);\n    throw new ApplicationException($\"Could not save '{path}': {ex.InnerException?.Message}\", ex);\n}","preventionTips":["Verify write permissions on the store root for the application identity at startup.","Monitor disk space on the volume hosting App_Data/media.","Keep paths short and free of invalid characters; avoid deep nesting near Windows MAX_PATH.","Always log InnerException - the outer message is intentionally generic."],"tags":["file-storage","io-failure","filesystem"],"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-15T23:17:13.987Z"}