Skip to main content
net10.0net11.0

TemporaryDirectory and TemporaryFile allow to create a disposable directory or file to store temporary data

Published
Nov 13, 2026
4d ago
Total Downloads
167.9K
167,922

Install

dotnet add package Meziantou.Framework.TemporaryDirectory --version 3.0.17
ProductVersions
.NET
net10.0net11.0

README

Meziantou.Framework.TemporaryDirectory

TemporaryDirectory

Create a unique empty folder that is deleted at the end of the scope.

using var temporaryDirectory = TemporaryDirectory.Create();
temporaryDirectory.CreateEmptyFile("test/demo.txt");
File.WriteAllText(temporaryDirectory.GetFullPath("foo.txt"), "bar");

TemporaryFile

Create a unique file that is deleted at the end of the scope.

// Generated name under the system temp folder
using var temporaryFile = TemporaryFile.Create();
File.WriteAllText(temporaryFile.FullPath, "content");

// Choose the file name; a unique parent folder is created for it
using var namedFile = TemporaryFile.Create("custom.txt");

// Choose the full path. The file must not already exist.
using var atPath = TemporaryFile.Create(FullPath.Combine(Path.GetTempPath(), $"custom-{Guid.NewGuid():N}.txt"));

Changes from Previous Version

No structural changes between v3.0.16 and v3.0.17.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.