Skip to content

FileSystem LocalFileSystem

github-actions[bot] edited this page Dec 4, 2026 · 1 revision

LocalFileSystem

LocalFileSystem, in the Blueprint.FileSystem.Local namespace, stores files under a directory on disk. Its constructor takes rootPath and publicBaseURL. It resolves a relative root against the process working directory and creates the root directory if needed.

Store and serve a product photo

Suppose the CMS runs from the web project directory and the web server serves wwwroot/assets at http://localhost:5051/assets/. Given an incoming photo at incoming/1.png, the CMS can write the file and obtain the URL used by the site.

using Blueprint.FileSystem;
using Blueprint.FileSystem.Local;

BlueprintFileSystem assets = new LocalFileSystem("wwwroot/assets", new Uri("http://localhost:5051/assets/"));
assets.CreateDirectory("Products/Photos");

using (Stream photo = File.OpenRead("incoming/1.png"))
{
    assets.WriteFile("Products/Photos/1.png", photo);
}

Uri photoUrl = assets.GetPublicUrl("Products/Photos/1.png");
// http://localhost:5051/assets/Products/Photos/1.png

Local file operations

Use an application-controlled storage directory. Pass paths relative to that directory, with forward slashes between names. For batch operations, pass the directory as path and supply individual file names in the list.

Method Local behavior
FileExists(path) Returns true if the path identifies an existing file. Returns false for a directory or a missing file.
DirectoryExists(path) Returns true if the path identifies an existing directory. Returns false for a file or a missing directory.
GetFiles(path) Returns a List<string> of file names directly inside the directory. An empty directory yields an empty list.
GetDirectories(path) Returns a List<string> of immediate subdirectory names. If the directory has no subdirectories, the list is empty.
CreateDirectory(path) Creates the directory and any missing parent directories. Succeeds when the directory already exists.
DeleteDirectory(path, recursiveDelete = false) Deletes an empty directory. A nonempty directory causes an IOException by default. Pass recursiveDelete: true to delete the directory and all its contents.
ReadFile(path) Opens a read-only Stream at the first byte. Dispose it to release the file handle.
ReadFiles(path, fileNames) Returns a List<Stream> of independent read-only streams in file-name order. Dispose each stream. If a file fails to open, the provider closes the streams it already opened.
WriteFile(path, content) Creates or truncates the destination file in an existing directory. Copies from the current position of content and leaves the source stream open.
WriteFiles(path, streams, finalNames) Requires one final name per stream. Writes streams[i] to finalNames[i] in order, with the same overwrite and stream ownership rules as WriteFile.
MoveFile(sourcePath, destinationPath) Moves or renames a file. The destination directory must exist. A different file already at the destination causes the move to fail.
DeleteFile(path) Deletes the file directly. Succeeds when the parent directory exists and the file is already absent.
DeleteFiles(path, fileNames) Applies DeleteFile semantics to each name in order. A deletion error stops the batch.
GetPublicUrl(path) Returns an absolute Uri under publicBaseURL, encoding each name in the relative path. This inherited method performs no disk access.

Writes go directly to the final names. An interrupted write can leave a partial file. If a write or delete batch fails, earlier writes or deletions remain in effect.

Related topics

BlueprintFileSystem API · FtpFileSystem · Class source · User manual

Clone this wiki locally