OrchardCMS/OrchardCore · error · FileStoreException
Cannot get directories with path
Error message
Cannot get directories with path '{path}'. What it means
FileSystemStore.GetDirectoriesAsync lists only subdirectories under a path and wraps enumeration exceptions in a FileStoreException with this message. A path with no subdirectories returns empty rather than throwing; this error indicates an I/O failure during listing.
Solutions
- Read the InnerException: UnauthorizedAccessException -> fix ACLs; DirectoryNotFoundException -> path removed; IOException -> lock or device issue.
- Grant the app identity list permissions recursively over the storage root.
- Sanitize folder names (strip invalid path characters) when creating folders from user input.
- Verify the path exists first via GetDirectoryInfoAsync.
Example fix
// before
var dirs = fileStore.GetDirectoriesAsync(path);
await foreach (var d in dirs) { ... }
// after
try
{
var dirs = fileStore.GetDirectoriesAsync(path);
await foreach (var d in dirs) { ... }
}
catch (FileStoreException ex)
{
logger.LogWarning(ex.InnerException, "Could not list directories under {Path}", path);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (await fileStore.GetDirectoryInfoAsync(path) == null)
{
return AsyncEnumerable.Empty<IFileStoreEntry>();
} Try / catch
try
{
await foreach (var d in fileStore.GetDirectoriesAsync(path)) { /* ... */ }
}
catch (FileStoreException ex)
{
logger.LogError(ex.InnerException, "Directory listing failed for {Path}", path);
} Prevention
- Sanitize folder names created from user input
- Ensure recursive list permissions on the storage root
- Confirm network shares are mounted before serving media
- Verify path existence before enumerating
When it happens
Trigger: Calling IFileStore.GetDirectoriesAsync(path) when Directory.EnumerateDirectories throws: UnauthorizedAccessException on an unreadable subfolder, invalid/too-long path, directory deleted during enumeration, or volume/device errors.
Common situations: Media library folder tree broken by ACL changes; enumerating folders on a disconnected network share; invalid characters introduced by user-created folder names; indexer/AV interference.
Related errors
- Cannot get directory content with path
- Cannot get files with path
- Cannot get directory info with path
- Cannot get file info with path
- Cannot copy file ' ' to ' '.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/c713c9df7b2900d3.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:167
{
return Array.Empty<IFileStoreEntry>().ToAsyncEnumerable();
}
var results = Directory
.GetDirectories(physicalPath, "*", SearchOption.TopDirectoryOnly)
.Select(f =>
{
var fileSystemInfo = new PhysicalDirectoryInfo(new DirectoryInfo(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 directories with path '{path}'.", ex);
}
}
public Task<bool> TryCreateDirectoryAsync(string path)
{
try
{
var physicalPath = GetPhysicalPath(path);
if (File.Exists(physicalPath))
{
throw new FileStoreException($"Cannot create directory because the path '{path}' already exists and is a file.");
}
if (Directory.Exists(physicalPath))
{
return Task.FromResult(false);
}View on GitHub (pinned to 4306c0717f)