{"record":{"id":"d9c60a1f8af1a00a","repo":"OrchardCMS/OrchardCore","slug":"cannot-get-file-stream-because-the-file-path-does-not-exist-d9c60a","errorCode":null,"errorMessage":"Cannot get file stream because the file '{path}' does not exist.","messagePattern":"Cannot get file stream because the file '(.+?)' does not exist\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs","lineNumber":315,"sourceCode":"        catch (FileStoreException)\n        {\n            throw;\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot copy file '{srcPath}' to '{dstPath}'.\", ex);\n        }\n    }\n\n    public Task<Stream> GetFileStreamAsync(string path)\n    {\n        try\n        {\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    {","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs#L297-L333","documentation":"FileSystemStore.GetFileStreamAsync throws FileStoreException when the requested store-relative path does not map to an existing file on disk. Before opening the stream the store calls GetPhysicalPath(path) and checks File.Exists; if absent, it throws this error instead of returning a null stream. It is a guard so callers get a consistent exception type from the IFileStore abstraction rather than a raw FileNotFoundException.","triggerScenarios":"Calling await fileStore.GetFileStreamAsync(path) with a store-relative path (e.g. 'sites/tenant/media/doc.pdf') whose underlying physical file does not exist — wrong path, deleted file, or a directory path instead of a file path.","commonSituations":"Path built from user input or a content-item field without checking GetFileInfoAsync first; file deleted by another process or cleanup job between listing and reading; media stored on a different volume/tenant than the one queried; case-sensitivity mismatch on Linux causing the physical path to miss.","solutions":["Call await fileStore.GetFileInfoAsync(path) and verify it is not null (and not a directory) before requesting the stream.","Verify the path is store-relative (no leading slash, no app-root or absolute filesystem path) — GetPhysicalPath prefixes the store root, so absolute or double-rooted paths resolve to non-existent locations.","Check the file actually exists on disk under the store root and that the process identity has read access to that directory.","Wrap the call in try/catch on FileStoreException and fall back to a 404/default-asset response when the file is optional."],"exampleFix":"// before\nvar stream = await _fileStore.GetFileStreamAsync(model.UserSuppliedPath);\n\n// after\nvar file = await _fileStore.GetFileInfoAsync(model.UserSuppliedPath);\nif (file == null || file.IsDirectory)\n{\n    return NotFound();\n}\nvar stream = await _fileStore.GetFileStreamAsync(file.Path);","handlingStrategy":"validation","validationCode":"var fileInfo = await fileStore.GetFileInfoAsync(path);\nif (fileInfo is null || fileInfo.IsDirectory)\n{\n    // treat as missing: skip, return 404, etc.\n    return;\n}","typeGuard":"static bool FileExists(IFileStore store, string path) => store.GetFileInfoAsync(path).GetAwaiter().GetResult() is { IsDirectory: false };","tryCatchPattern":"try\n{\n    var stream = await fileStore.GetFileStreamAsync(path);\n    using (stream) { /* ... */ }\n}\ncatch (FileStoreException ex)\n{\n    logger.LogWarning(ex, \"File '{Path}' not found in store\", path);\n    return Results.NotFound();\n}","preventionTips":["Always resolve paths through IFileStore APIs, never concatenate absolute filesystem paths yourself.","Check GetFileInfoAsync before opening streams in request handlers.","Remember Linux case sensitivity — keep media paths canonical.","Use the IFileStoreEntry overload only with freshly fetched entries."],"tags":["file-storage","file-not-found","filesystem"],"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-15T23:17:13.987Z"}