OrchardCMS/OrchardCore · error · FileStoreException

Cannot get files with path

Error message

Cannot get files with path '{path}'.

What it means

FileSystemStore.GetFilesAsync lists only files under a path (with optional subdirectory search in some flows) and wraps enumeration exceptions in a FileStoreException with this message. It is the file-focused variant of GetDirectoryContentAsync and fails for the same I/O reasons.

Solutions

  1. Inspect the InnerException to identify the concrete System.IO error and address it (permissions, path validity, existence).
  2. Ensure read permissions on all levels of the storage root subtree.
  3. Validate/shorten the path if MAX_PATH or invalid characters are implicated.
  4. Check the folder was not deleted or renamed by a concurrent process before listing.

Example fix

// before
var files = fileStore.GetFilesAsync("media");
// after
try
{
    var files = fileStore.GetFilesAsync("media");
}
catch (FileStoreException ex)
{
    logger.LogError(ex.InnerException, "Failed to list files in media");
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (await fileStore.GetDirectoryInfoAsync(path) == null)
{
    return AsyncEnumerable.Empty<IFileStoreEntry>();
}

Try / catch

try
{
    await foreach (var f in fileStore.GetFilesAsync(path)) { /* ... */ }
}
catch (FileStoreException ex) when (ex.InnerException is UnauthorizedAccessException)
{
    logger.LogWarning("Access denied listing files in {Path}", path);
}

Prevention

When it happens

Trigger: Calling IFileStore.GetFilesAsync(path) when the underlying file enumeration throws: access denied, path invalid or too long, or the directory disappears mid-enumeration.

Common situations: Media listing pages after the folder backing the store was moved; restrictive ACLs on subfolders; long-path issues on Windows; file locks from other services during listing.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/26b6dd90082d73ea. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:138

            {
                return Array.Empty<IFileStoreEntry>().ToAsyncEnumerable();
            }

            var results = Directory
                .GetFiles(physicalPath, "*", SearchOption.TopDirectoryOnly)
                .Select(f =>
                {
                    var fileSystemInfo = new PhysicalFileInfo(new FileInfo(f));
                    var fileRelativePath = f[_fileSystemPath.Length..];
                    var filePath = this.NormalizePath(fileRelativePath);
                    return (IFileStoreEntry)new FileSystemStoreEntry(filePath, fileSystemInfo);
                });

            return results.ToAsyncEnumerable();
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot get files with path '{path}'.", ex);
        }
    }

    public IAsyncEnumerable<IFileStoreEntry> GetDirectoriesAsync(string path = null)
    {
        try
        {
            var physicalPath = GetPhysicalPath(path);

            if (!Directory.Exists(physicalPath))
            {
                return Array.Empty<IFileStoreEntry>().ToAsyncEnumerable();
            }

            var results = Directory
                .GetDirectories(physicalPath, "*", SearchOption.TopDirectoryOnly)
                .Select(f =>
                {

View on GitHub (pinned to 4306c0717f)