{"record":{"id":"4506d53863d67942","repo":"OrchardCMS/OrchardCore","slug":"cannot-create-directory-path-filesystemstore","errorCode":null,"errorMessage":"Cannot create directory '{path}'.","messagePattern":"Cannot create directory '(.+?)'\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs","lineNumber":197,"sourceCode":"                throw new FileStoreException($\"Cannot create directory because the path '{path}' already exists and is a file.\");\n            }\n\n            if (Directory.Exists(physicalPath))\n            {\n                return Task.FromResult(false);\n            }\n\n            Directory.CreateDirectory(physicalPath);\n\n            return Task.FromResult(true);\n        }\n        catch (FileStoreException)\n        {\n            throw;\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot create directory '{path}'.\", ex);\n        }\n    }\n\n    public Task<bool> TryDeleteFileAsync(string path)\n    {\n        try\n        {\n            var physicalPath = GetPhysicalPath(path);\n\n            if (!File.Exists(physicalPath))\n            {\n                return Task.FromResult(false);\n            }\n\n            File.Delete(physicalPath);\n\n            return Task.FromResult(true);\n        }","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs#L179-L215","documentation":"Generic catch-all in TryCreateDirectoryAsync: any unexpected exception from Directory.CreateDirectory (IO errors, unauthorized access, invalid path characters, disk full) is rethrown as FileStoreException with this message and the original exception as InnerException. It is not thrown for pre-existing directories (those return false).","triggerScenarios":"TryCreateDirectoryAsync(path) when the underlying Directory.CreateDirectory throws: access denied, read-only volume, illegal characters in the mapped physical path, path too long, or disk full.","commonSituations":"App pool identity lacks write permission to App_Data/media; running on a read-only container filesystem; invalid characters in tenant-generated folder names; MAX_PATH issues on Windows.","solutions":["Inspect the InnerException of the FileStoreException for the real cause.","Grant write permission on the storage root to the application identity.","Sanitize/validate the path components before calling TryCreateDirectoryAsync."],"exampleFix":"// before\nawait store.TryCreateDirectoryAsync(userInput);\n// after\nvar safe = string.Concat(userInput.Split(Path.GetInvalidFileNameChars()));\nawait store.TryCreateDirectoryAsync(safe);","handlingStrategy":"try-catch","validationCode":"if (path.Split('/', StringSplitOptions.RemoveEmptyEntries).Any(p => p.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)) throw new ArgumentException($\"Invalid path segment in '{path}'\");","typeGuard":"static bool IsValidStorePath(string path) => !string.IsNullOrWhiteSpace(path) && path.IndexOfAny(Path.GetInvalidPathChars()) < 0;","tryCatchPattern":"try { await store.TryCreateDirectoryAsync(path); }\ncatch (FileStoreException ex)\n{\n    _logger.LogError(ex.InnerException, \"Directory creation failed for {Path}\", path);\n    throw;\n}","preventionTips":["Grant the app identity write access to the storage root (App_Data).","Sanitize user-supplied path segments.","Monitor disk space on the storage volume."],"tags":["filesystem","io","file-store"],"backgroundTag":"file-write-failed","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}