OrchardCMS/OrchardCore · error · FileStoreException

Cannot create file ' '.

Error message

Cannot create file '{path}'.

What it means

CreateFileFromStreamAsync wraps any non-FileStoreException failure while uploading the blob (content-type resolution, OpenWrite/Upload of the stream, HTTP headers) in a FileStoreException with this message. The inner exception contains the underlying Azure Storage error.

Solutions

  1. Inspect the InnerException (RequestFailedException Status) for the actual cause: 403 auth, 404 container missing, 429 throttling, 400 bad request/path.
  2. Verify the input stream is readable, not disposed, and positioned at 0 before calling.
  3. Check the storage connection string, account status, and that the target container exists.
  4. Validate the path contains only valid blob name characters and proper forward-slash separators.

Example fix

// before
await fileStore.CreateFileFromStreamAsync(path, stream);
// after
if (!stream.CanRead)
{
    throw new InvalidOperationException("Input stream is not readable.");
}
stream.Position = 0;
await fileStore.CreateFileFromStreamAsync(path, stream);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!stream.CanRead) throw new InvalidOperationException("Stream not readable");
stream.Position = 0;
foreach (var c in Path.GetInvalidFileNameChars())
{
    path = path.Replace(c, '_');
}

Try / catch

try
{
    await fileStore.CreateFileFromStreamAsync(path, stream);
}
catch (FileStoreException ex)
{
    logger.LogError(ex.InnerException, "Create failed for {Path}", path);
    throw;
}

Prevention

When it happens

Trigger: Calling IFileStore.CreateFileFromStreamAsync(path, stream) when the Azure SDK upload throws: auth failure, container missing, invalid path characters, zero/disposed input stream, throttling, or exceeding storage limits.

Common situations: Bad storage connection string or disabled account; media uploads during a storage outage; passing a stream that was already disposed or empty by an upstream bug; blob names with characters Azure rejects (e.g. '\\', trailing dot).

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/8665d7608a6ba545. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs:687

            _contentTypeProvider.TryGetContentType(path, out var contentType);

            var headers = new BlobHttpHeaders
            {
                ContentType = contentType ?? MediaTypeNames.Application.Octet,
            };

            await blob.UploadAsync(inputStream, headers);

            return path;
        }
        catch (FileStoreException)
        {
            throw;
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot create file '{path}'.", ex);
        }
    }

    private BlobClient GetBlobReference(string path)
    {
        var blobPath = this.Combine(_options.BasePath, path);
        var blob = _blobContainer.GetBlobClient(blobPath);

        return blob;
    }

    private async Task<BlobHierarchyItem> GetBlobDirectoryReference(string path)
    {
        var prefix = this.Combine(_basePrefix, path);
        prefix = NormalizePrefix(prefix);

        // Directory exists if path contains any files.
        var page = _blobContainer.GetBlobsByHierarchyAsync(BlobTraits.Metadata, BlobStates.None, "/", prefix, CancellationToken.None);

View on GitHub (pinned to 4306c0717f)