Oakrey.Applications.Files 8.0.0

dotnet add package Oakrey.Applications.Files --version 8.0.0
                    
NuGet\Install-Package Oakrey.Applications.Files -Version 8.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Applications.Files" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.Files" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Applications.Files" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Applications.Files --version 8.0.0
                    
#r "nuget: Oakrey.Applications.Files, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Applications.Files@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Applications.Files&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.Files&version=8.0.0
                    
Install as a Cake Tool

Oakrey.Applications.Files

A .NET 11 class library that provides file and directory management through a single injectable service interface. It supports synchronous and asynchronous reads, age-based cleanup, OpenTelemetry tracing, and exception-aware logging.

Main features

  • Read file content as a string, synchronously or asynchronously with CancellationToken support
  • Read and write files via FileStream
  • Save text content to a file with automatic intermediate directory creation
  • Create directories on demand
  • Delete a single file by path
  • Delete files in a directory that are older than a given TimeSpan, with optional extension filter
  • Enumerate all file paths in a directory tree by extension
  • Recursive enumeration skips reparse points to avoid leaving the requested directory tree through links
  • Every operation emits an OpenTelemetry activity span and log entries via Oakrey.Log

Architecture

classDiagram
    class IFileService {
        +CreateFolder(folderName)
        +CreateSaveStream(fileName) FileStream
        +DeleteFile(fileName)
        +DeleteFileOlderThan(path, timeSpan, extension, ct) Task
        +GetFilesPaths(folder, extension) string[]
        +LoadFile(fileName) string
        +LoadFileAsync(fileName, ct) Task~string~
        +LoadFileStream(fileName) FileStream
        +SaveFile(fileName, value)
    }

    class FileService {
        -ILogger logger
        -ITracing tracer
        +FileService()
    }

    IFileService <|.. FileService

Requirements

  • .NET 11 or higher
  • Oakrey.Log.Abstractions 3.0.0 or higher
  • Oakrey.Telemetry 2.0.1 or higher

Installation

NuGet Package Manager

  1. In Visual Studio open Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
  2. Search for Oakrey.Applications.Files and click Install.

.NET CLI

dotnet add package Oakrey.Applications.Files

Package Manager Console

Install-Package Oakrey.Applications.Files

Configuration

FileService has no required configuration. Register it with the DI container of your choice:

// Microsoft.Extensions.DependencyInjection
services.AddSingleton<IFileService, FileService>();

Oakrey.Log and Oakrey.Telemetry must be configured separately according to their own documentation before FileService is resolved.

Example usage

public class ReportExporter(IFileService fileService)
{
    // Save a text report, directories are created automatically
    public void SaveReport(string path, string content)
    {
        fileService.SaveFile(path, content);
    }

    // Load a text report asynchronously
    public async Task<string> LoadReportAsync(string path, CancellationToken ct)
    {
        return await fileService.LoadFileAsync(path, ct);
    }

    // Write binary output via stream
    public FileStream OpenWriteStream(string path)
    {
        return fileService.CreateSaveStream(path);
    }

    // Remove log files older than 30 days
    public Task CleanupLogsAsync(string logDirectory, CancellationToken ct)
    {
        return fileService.DeleteFileOlderThan(logDirectory, TimeSpan.FromDays(30), "log", ct);
    }

    // List all CSV files in a directory tree
    public string[] GetCsvFiles(string root)
    {
        return fileService.GetFilesPaths(root, "csv");
    }
}

Development notes

  • SaveFile is synchronous, matching the IFileService contract, so write failures are propagated directly to the caller.
  • DeleteFileOlderThan compares LastWriteTimeUtc with the complete TimeSpan and respects CancellationToken between file deletions.
  • Recursive enumeration skips reparse points and sorts results using ordinal case-insensitive ordering.
  • Failures are logged with their exception objects. Log messages use only the terminal file or directory name to reduce disclosure of sensitive path information.
  • All operations start an OpenTelemetry Activity via Oakrey.Telemetry.Tracing; configure an exporter in the host to capture traces.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author: Oakrey
Repository: https://dev.azure.com/oakrey/OpenPackages/_git/ApplicationServices
Project URL: https://www.oakrey.cz/opkg_applications

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Oakrey.Applications.Files:

Package Downloads
Oakrey.Applications.Base

A foundational .NET library for building modular WPF applications. Provides application lifecycle management, MVVM ViewModel resolution, structured logging, telemetry, and sequential or parallel service preloading with full unhandled-exception coverage.

Oakrey.Applications.SecureSettings

Readable JSON secured settings service for critical values stored in SecuredSettings.json, with HMAC integrity protection, Windows-user authorization, audit history, and an explicit ISecuredSettingsService API that can run beside regular Settings.json settings.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.0 50 11/15/2026
7.0.0 278 7/20/2026
6.0.2 150 7/8/2026
6.0.1 142 7/3/2026
6.0.0 151 5/22/2026
3.0.3 135 5/22/2026
3.0.2 163 5/15/2026
3.0.1 197 2/11/2026
3.0.0 487 11/18/2025
2.1.1 333 9/29/2025
2.1.0 272 9/23/2025
2.0.0 389 6/9/2025
1.0.0 344 4/17/2025