OrchardCMS/OrchardCore · error · FileStoreException

Cannot create directory

Error message

Cannot create directory '{path}'.

What it means

In BlobFileStore.TryCreateDirectoryAsync, when the account uses Hierarchical Namespace the creation is done via TryCreateDataLakeDirectoryAsync; any exception there is wrapped in a FileStoreException with this message. Unlike the flat-namespace path (which pretends success), DataLake directories are real filesystem nodes, so a failure to create them is surfaced.

Solutions

  1. Check the inner exception: 403 means grant Storage Blob Data Contributor (plus execute/Write ACLs) to the identity on the filesystem/path.
  2. Verify the path is valid for DataLake (no empty segments, no illegal characters, not colliding with an existing file).
  3. Confirm the account/filesystem (container) names are correct in options.
  4. Retry on transient 5xx errors; the method normally returns false instead of throwing only for benign outcomes.

Example fix

// before
await fileStore.TryCreateDirectoryAsync("reports//2026"); // empty segment
// after
await fileStore.TryCreateDirectoryAsync("reports/2026");
Defensive patterns

Strategy: validation

Validate before calling

var segments = path.Split('/', StringSplitOptions.RemoveEmptyEntries);
if (segments.Length == 0 || segments.Any(string.IsNullOrWhiteSpace))
{
    return false; // reject invalid directory path before calling
}
if (await fileStore.GetFileInfoAsync(path) != null)
{
    return false; // path is an existing file
}

Try / catch

try
{
    var ok = await fileStore.TryCreateDirectoryAsync(path);
    if (!ok) { /* handle benign failure */ }
}
catch (FileStoreException ex)
{
    logger.LogError(ex.InnerException, "DataLake directory creation failed for {Path}", path);
    // typically 403: grant Storage Blob Data Contributor + ACL execute/write
}

Prevention

When it happens

Trigger: Calling TryCreateDirectoryAsync on a Gen2/HNS account when the DataLake FileSystemClient.CreateDirectoryAsync (or equivalent) throws — permission denied on the filesystem, path conflicts with an existing blob, invalid path characters, or service errors.

Common situations: ACL/RBAC on the ADLS Gen2 filesystem denying write for the configured identity; creating a directory whose path collides with an existing blob name; invalid path segments (empty segments, illegal chars); transient service errors.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


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

Appendix: source

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

            {
                yield return new BlobFile(RemoveBasePrefix(name), blob.Properties.ContentLength, blob.Properties.LastModified);
            }
        }
    }

    public async Task<bool> TryCreateDirectoryAsync(string path)
    {
        await EnsureCapabilitiesAsync();

        if (_capabilities?.HasHierarchicalNamespace == true)
        {
            try
            {
                return await TryCreateDataLakeDirectoryAsync(path);
            }
            catch (Exception ex)
            {
                throw new FileStoreException($"Cannot create directory '{path}'.", ex);
            }
        }

        // Since directories are only created implicitly when creating blobs, we
        // simply pretend like we created the directory, unless there is already
        // a blob with the same path.
        try
        {
            var blobFile = GetBlobReference(path);

            if (await blobFile.ExistsAsync())
            {
                throw new FileStoreException($"Cannot create directory because the path '{path}' already exists and is a file.");
            }

            var blobDirectory = await GetBlobDirectoryReference(path);
            if (blobDirectory == null)
            {

View on GitHub (pinned to 4306c0717f)