OrchardCMS/OrchardCore · error · FileStoreException
Cannot create file ' '.
Error message
Cannot create file '{path}'. What it means
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.
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.
Example fix
// before
await fileStore.CreateFileFromStreamAsync(path, stream);
// after
try
{
await fileStore.CreateFileFromStreamAsync(path, stream);
}
catch (FileStoreException ex)
{
logger.LogError(ex.InnerException, "Failed to create file '{Path}': {Reason}", path, ex.InnerException?.Message);
throw;
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!Directory.Exists(Path.GetDirectoryName(physicalPath)))
{
throw new InvalidOperationException("Target directory does not exist or is not writable.");
} Try / catch
try
{
await fileStore.CreateFileFromStreamAsync(path, stream);
}
catch (FileStoreException ex)
{
logger.LogError(ex.InnerException ?? ex, "CreateFileFromStreamAsync failed for '{Path}'", path);
throw new ApplicationException($"Could not save '{path}': {ex.InnerException?.Message}", ex);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Cannot get file stream because the file
- Cannot create file ' ' because it already exists as a…
- returned a null .
- Error retrieving file info for
- Error creating directory
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/8b0e371aca1630e5.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:388
}
// Create directory path if it doesn't exist.
var physicalDirectoryPath = Path.GetDirectoryName(physicalPath);
Directory.CreateDirectory(physicalDirectoryPath);
var fileInfo = new FileInfo(physicalPath);
await using var outputStream = fileInfo.Create();
await inputStream.CopyToAsync(outputStream);
return path;
}
catch (FileStoreException)
{
throw;
}
catch (Exception ex)
{
throw new FileStoreException($"Cannot create file '{path}'.", ex);
}
}
public Task<long?> GetPermittedStorageAsync()
{
try
{
var path = GetPhysicalPath(null);
var driveOfStoreRoot = DriveInfo
.GetDrives()
.OrderByDescending(drive => drive.Name.Length)
.FirstOrDefault(drive => path.StartsWith(drive.Name));
return Task.FromResult(driveOfStoreRoot?.AvailableFreeSpace);
}
catch (Exception ex)
{
// It is possible, that the process only has limited access to the drive and trying to get this informationView on GitHub (pinned to 4306c0717f)