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

  1. Inspect the InnerException of the thrown FileStoreException to identify the real cause (IOException, UnauthorizedAccessException, etc.).
  2. Verify the app identity has write permission on the store root (App_Data or the configured media root).
  3. Check available disk space and remove path-length/invalid-character issues in the supplied path.
  4. If transient (locked file, network volume), wait and retry the operation.
  5. 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

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


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 information

View on GitHub (pinned to 4306c0717f)