{"record":{"id":"33a77c89e74690de","repo":"OrchardCMS/OrchardCore","slug":"cannot-get-file-stream-of-the-file-path-filesystemstore","errorCode":null,"errorMessage":"Cannot get file stream of the file '{path}'.","messagePattern":"Cannot get file stream of the file '(.+?)'\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs","lineNumber":328,"sourceCode":"        {\n            var physicalPath = GetPhysicalPath(path);\n\n            if (!File.Exists(physicalPath))\n            {\n                throw new FileStoreException($\"Cannot get file stream because the file '{path}' does not exist.\");\n            }\n\n            var stream = File.OpenRead(physicalPath);\n\n            return Task.FromResult<Stream>(stream);\n        }\n        catch (FileStoreException)\n        {\n            throw;\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot get file stream of the file '{path}'.\", ex);\n        }\n    }\n\n    public Task<Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)\n    {\n        try\n        {\n            var physicalPath = GetPhysicalPath(fileStoreEntry.Path);\n            if (!File.Exists(physicalPath))\n            {\n                throw new FileStoreException($\"Cannot get file stream because the file '{fileStoreEntry.Path}' does not exist.\");\n            }\n\n            var stream = File.OpenRead(physicalPath);\n\n            return Task.FromResult<Stream>(stream);\n        }\n        catch (FileStoreException)","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs#L310-L346","documentation":"This is the generic catch-all in FileSystemStore.GetFileStreamAsync(path): any exception other than FileStoreException while resolving or opening the file (File.OpenRead failures such as UnauthorizedAccessException, IOException, path-format errors) is wrapped in a FileStoreException with this message. The original exception is preserved as InnerException. It signals an unexpected failure reading the file, distinct from the explicit 'does not exist' check.","triggerScenarios":"GetFileStreamAsync(path) where GetPhysicalPath or File.OpenRead throws — e.g. unauthorized access, file locked by another process (IOException), path too long, invalid characters in path, or disk I/O failure.","commonSituations":"App pool identity lacks NTFS read permission on App_Data/media folders; antivirus or another worker holds the file open; path contains illegal characters from user input; directory unexpectedly removed mid-operation on network shares.","solutions":["Inspect exception.InnerException to identify the real cause (UnauthorizedAccessException vs IOException vs ArgumentException).","Grant the application identity read permission on the file store root directory.","Sanitize/normalize the path (reject invalid characters, excessive length) before passing it to GetFileStreamAsync.","Retry the open on IOException if a transient lock (antivirus/indexer) is suspected; otherwise fail gracefully with a 500."],"exampleFix":"// before\nvar stream = await _fileStore.GetFileStreamAsync(path);\n\n// after\ntry\n{\n    var stream = await _fileStore.GetFileStreamAsync(path);\n}\ncatch (FileStoreException ex) when (ex.InnerException is UnauthorizedAccessException)\n{\n    _logger.LogError(ex, \"No read permission for '{Path}'\", path);\n    return Forbid();\n}","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(path) || path.Contains('\"') || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)\n{\n    throw new ArgumentException(\"Invalid store path\", nameof(path));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    return await fileStore.GetFileStreamAsync(path);\n}\ncatch (FileStoreException ex)\n{\n    logger.LogError(ex.InnerException ?? ex, \"Could not open '{Path}' from file store\", path);\n    throw;\n}","preventionTips":["Always inspect InnerException to distinguish permissions, locking, and path-format problems.","Run the app identity with read access to the store root (App_Data / media folders).","Sanitize user-supplied filenames before persisting them into store paths.","Add retry-once logic for transient IOException on network/AV-locked volumes."],"tags":["file-storage","file-read-failed","io"],"backgroundTag":"file-read-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"}