ByteGuard.FileValidator.AspNetCore 10.0.0

Prefix Reserved
dotnet add package ByteGuard.FileValidator.AspNetCore --version 10.0.0
                    
NuGet\Install-Package ByteGuard.FileValidator.AspNetCore -Version 10.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="ByteGuard.FileValidator.AspNetCore" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ByteGuard.FileValidator.AspNetCore" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ByteGuard.FileValidator.AspNetCore" />
                    
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 ByteGuard.FileValidator.AspNetCore --version 10.0.0
                    
#r "nuget: ByteGuard.FileValidator.AspNetCore, 10.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 ByteGuard.FileValidator.AspNetCore@10.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=ByteGuard.FileValidator.AspNetCore&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ByteGuard.FileValidator.AspNetCore&version=10.0.0
                    
Install as a Cake Tool

ByteGuard.FileValidator.AspNetCore NuGet Version

ByteGuard.FileValidator.AspNetCore provides first-class integration of ByteGuard.FileValidator with ASP.NET Core.

It gives you:

  • Extension methods to register the file validator in the DI container
  • Easy configuration via appsettings.json or fluent configuration in code
  • A single, consistent way to validate uploaded files across your ASP.NET Core apps

This package is the ASP.NET Core integration layer. The core validation logic lives in ByteGuard.FileValidator.

Getting Started

Installation

This package is published and installed via NuGet.

Reference the package in your project:

dotnet add package ByteGuard.FileValidator.AspNetCore

Usage

Add to DI container

In your Program.cs (or Startup.cs in older projects), register the validator:

using ByteGuard.FileValidator.AspNetCore;

// Using inline configuration
builder.Services.AddFileValidator(options => 
{
    options.AllowFileTypes(FileExtensions.Pdf, FileExtensions.Jpg, FileExtensions.Png);
    options.FileSizeLimit = ByteSize.MegaBytes(25);
    options.ThrowOnInvalidFiles(false);
});

// Using configuration from appsettings.json
builder.Services.AddFileValidator(options => configuration.GetSection("FileValidatorConfiguration").Bind(options));

Injection & Usage

You can then inject FileValidator into your services and other classes.

public class MyService
{
    private readonly FileValidator _fileValidator;

    public MyService(FileValidator fileValidator)
    {
        _fileValidator = fileValidator;
    }

    public bool SaveFile(Stream fileStream, string fileName)
    {
        var isValid = _fileValidator.IsValidFile(fileName, fileStream);
        
        // ...
    }
}

Configuration via appsettings

It's possible to configure the FileValidator through appsettings.json.

ℹ️ As you'll notice below, you can either define the FileSizeLimit in raw byte size, or use the FriendlyFileSizeLimit to define the file size in a more human readable format. When both are defined, FileSizeLimit always wins over FriendlyFileSizeLimit.

{
  "FileValidatorConfiguration": {
    "SupportedFileTypes": [ ".pdf", ".jpg", ".png" ],
    "FileSizeLimit": 26214400,
    "FriendlyFileSizeLimit": "25MB",
    "ThrowExceptionOnInvalidFile": true
  }
}

License

ByteGuard.FileValidator.AspNetCore is Copyright © ByteGuard Contributors - Provided under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 259 11/24/2025 10.0.0 is deprecated because it is no longer maintained.