OrchardCMS/OrchardCore · error · FileStoreException
Cannot create directory because the path
Error message
Cannot create directory because the path '{path}' already exists and is a file. What it means
BlobFileStore.TryCreateDirectoryAsync (flat-namespace path) checks whether a blob already exists at the requested path; because blob 'directories' are only implied by prefixes, a real blob at that exact path means the directory cannot be created. The store throws FileStoreException with this message naming the conflicting path.
Solutions
- Choose a different directory name, or delete the conflicting blob first (TryDeleteFileAsync at that path).
- Treat it like a file-exists condition in app logic: check GetFileInfoAsync(path) before creating a directory.
- Adopt naming conventions that keep file keys and directory prefixes disjoint (e.g. always give files extensions).
- If the collision was a mistake, re-upload the blob under a proper file path and retry the directory creation.
Example fix
// before
if (await fileStore.GetFileInfoAsync(path) != null)
{
throw new InvalidOperationException("Path in use");
}
await fileStore.TryCreateDirectoryAsync(path);
// after
if (await fileStore.GetFileInfoAsync(path) != null)
{
path = path + "-folder"; // avoid blob-file collision
}
await fileStore.TryCreateDirectoryAsync(path); Defensive patterns
Strategy: validation
Validate before calling
var existingFile = await fileStore.GetFileInfoAsync(path);
if (existingFile != null)
{
// a blob exists at this exact key — pick another name or delete it first
return false;
} Try / catch
try
{
var created = await fileStore.TryCreateDirectoryAsync(path);
}
catch (FileStoreException ex) when (ex.Message.Contains("already exists and is a file"))
{
// path collides with an existing blob: rename or delete the blob
await fileStore.TryDeleteFileAsync(path);
await fileStore.TryCreateDirectoryAsync(path);
} Prevention
- Keep file keys and directory prefixes disjoint (e.g. require extensions on files).
- Check GetFileInfoAsync before creating a directory with a user-supplied name.
- Audit legacy content for blobs that double as would-be folder names.
- Surface a clear UI message when a user names a folder identically to an existing file.
When it happens
Trigger: Calling TryCreateDirectoryAsync(path) on a flat (non-HNS) account where a blob was previously uploaded with exactly that key — e.g. a file named 'docs' exists and code then tries TryCreateDirectoryAsync("docs").
Common situations: Uploading files without extensions that later collide with intended directory names; older uploads that used the path as a file key; migrations from other stores where keys were used both as files and folders; user-driven naming where a folder shares a name with an uploaded file.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Cannot get file info with path
- Cannot get directory info with path
- Cannot get directory content with path
- Cannot create directory
- Cannot delete file ' '.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/56779515cc84e263.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs:442
{
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)
{
await CreateDirectoryAsync(path);
}
return true;
}
catch (FileStoreException)
{
throw;
}
catch (Exception ex)
{
throw new FileStoreException($"Cannot create directory '{path}'.", ex);
}View on GitHub (pinned to 4306c0717f)