Soenneker.Utils.File
4.0.2239
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.File --version 4.0.2239
NuGet\Install-Package Soenneker.Utils.File -Version 4.0.2239
<PackageReference Include="Soenneker.Utils.File" Version="4.0.2239" />
<PackageVersion Include="Soenneker.Utils.File" Version="4.0.2239" />
<PackageReference Include="Soenneker.Utils.File" />
paket add Soenneker.Utils.File --version 4.0.2239
#r "nuget: Soenneker.Utils.File, 4.0.2239"
#:package Soenneker.Utils.File@4.0.2239
#addin nuget:?package=Soenneker.Utils.File&version=4.0.2239
#tool nuget:?package=Soenneker.Utils.File&version=4.0.2239
Soenneker.Utils.File
DI-friendly asynchronous file reading, writing, copying, moving, enumeration, metadata, and cleanup operations.
Installation
dotnet add package Soenneker.Utils.File
Registration
builder.Services.AddFileUtilAsSingleton();
AddFileUtilAsScoped() is also available and registers the memory-stream dependency with the matching lifetime.
Read and write
string text = await files.Read(path, cancellationToken: cancellationToken);
List<string> lines = await files.ReadAsLines(path, cancellationToken: cancellationToken);
byte[] bytes = await files.ReadToBytes(path, cancellationToken: cancellationToken);
await files.Write(path, text, cancellationToken: cancellationToken);
await files.Append(path, "next entry\n", cancellationToken: cancellationToken);
Text writes use UTF-8 without a byte-order mark. Reads detect a byte-order mark when present. Whole-file methods materialize the complete contents; use OpenRead() for large or streaming workloads.
TryRead() and TryReadToHashSet() return null and optionally log when reading fails. Requested cancellation still throws OperationCanceledException rather than being converted to null.
Stream ownership
await using FileStream input = files.OpenRead(path);
await using FileStream output = files.OpenWrite(destinationPath);
using MemoryStream buffered = await files.ReadToMemoryStream(path, cancellationToken: cancellationToken);
The caller owns every stream returned by this package. OpenWrite() creates missing parent directories and truncates an existing file. Write(path, sourceStream) copies from the source's current position, leaves the source open, and replaces the destination contents.
Copy and move
await files.Copy(sourcePath, destinationPath, cancellationToken: cancellationToken);
await files.Move(sourcePath, archivePath, cancellationToken: cancellationToken);
await files.CopyRecursively(sourceDirectory, destinationDirectory, cancellationToken: cancellationToken);
Copy() creates the destination parent and overwrites the destination. It is not transactional: a failed or cancelled copy can leave a partial destination.
Move() uses the filesystem's native overwrite move when available. Its cross-volume fallback copies to a temporary file beside the destination, publishes that completed copy, then deletes the source. If cancellation occurs after publication but before source deletion, both complete files can remain.
Recursive copy skips inaccessible entries and does not follow symbolic links, junctions, or other reparse points. It copies discovered files and their required parent directories; empty source directories are not reproduced.
Deletion and bulk mutation
bool removed = await files.DeleteIfExists(path, cancellationToken: cancellationToken);
await files.DeleteAll(directory, cancellationToken: cancellationToken);
DeleteAll() removes only files immediately inside the directory, not descendants. TryDelete(), TryDeleteIfExists(), and TryDeleteAll() convert I/O failures to false, but propagate requested cancellation.
Bulk rename, attribute removal, recursive copy, and multi-file deletion are incremental operations. Cancellation or a later conflict does not undo earlier filesystem changes. Resolve and validate any user-controlled root path before calling destructive methods.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Soenneker.Extensions.Stream (>= 4.0.146)
- Soenneker.Utils.ExecutionContexts (>= 4.0.39)
- Soenneker.Utils.MemoryStream (>= 4.0.1520)
NuGet packages (37)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.File:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.Json
Serializes, deserializes, validates, formats, and writes JSON with System.Text.Json or Newtonsoft.Json. |
|
|
Soenneker.Git.Util
Asynchronous Git operations, repository discovery, and bounded batch processing using bundled Git distributions. |
|
|
Soenneker.Utils.Dotnet
A utility library for the dotnet executable |
|
|
Soenneker.Google.Credentials
An async thread-safe singleton for Google OAuth credentials |
|
|
Soenneker.Utils.File.Download
Provides a flexible utility for downloading files from specified URIs, with thread-safe concurrency and automatic file name conflict handling |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.2246 | 2,461 | 9/1/2026 |
| 4.0.2245 | 803 | 8/31/2026 |
| 4.0.2244 | 64 | 8/31/2026 |
| 4.0.2243 | 946 | 8/31/2026 |
| 4.0.2242 | 3,003 | 8/31/2026 |
| 4.0.2241 | 5,751 | 8/31/2026 |
| 4.0.2240 | 1,772 | 8/31/2026 |
| 4.0.2239 | 2,711 | 8/31/2026 |
| 4.0.2238 | 120 | 8/30/2026 |
| 4.0.2237 | 1,180 | 8/30/2026 |
| 4.0.2235 | 5,305 | 8/30/2026 |
| 4.0.2234 | 3,118 | 8/30/2026 |
| 4.0.2233 | 75 | 8/30/2026 |
| 4.0.2232 | 156 | 8/30/2026 |
| 4.0.2231 | 1,535 | 8/29/2026 |
| 4.0.2230 | 7,362 | 8/29/2026 |
| 4.0.2228 | 103 | 8/29/2026 |
| 4.0.2227 | 350 | 8/29/2026 |
| 4.0.2226 | 30,604 | 8/26/2026 |
| 4.0.2223 | 12,970 | 8/22/2026 |
Update dependency Soenneker.Utils.ExecutionContexts to 4.0.39 (#3057)