Zhomfr.Validation.Rules.Files 0.6.0

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

Validation Rules for Files

NuGet Status NuGet Downloads

⚠️ Warning: Active Development (< 1.0.0)

Prior to the release of stable version 1.0.0, this library follows SemVer for initial development. This means breaking changes may occur even in minor releases (0.x).

We strongly recommend pinning the package version in your .csproj to avoid unexpected build errors.

A powerful, intuitive collection of custom validation attributes built directly on top of the standard .NET System.ComponentModel.DataAnnotations infrastructure. Designed to eliminate boilerplate code, this library brings a rich set of production-ready validation rules—inspired by robust ecosystem standards (like Laravel's validation features) — allowing you to validate models with SmartFiles cleanly using declarative attributes without reinventing the wheel.

Key Features

  • Standard DataAnnotations Integration: Seamlessly works with ASP.NET Core and standard Validator methods out of the box.
  • Rich Set of Built-in Rules: Covers frequent validation scenarios that are missing from standard .NET, preventing you from writing repetitive custom validators over and over again.
  • Intuitive Declarative Syntax: Clean and expressive attributes to keep your domain models and DTOs readable and maintainable.
  • Customizable Error Messages: Fully supports localized and custom error message templates via standard ErrorMessage properties.

📦 Installation

Install package:

dotnet add package Zhomfr.Validation.Rules.Files

After add namespace in using section:

using Zhomfr.Validation.Rules.Files;

Available Methods

<table> <tr valign="top"> <td>

</td> <td>

</td> <td>

</td> </tr> </table>

🛠️ Features and Examples

FileBetween

Validates that the file size (in bytes) falls within the specified inclusive range.

public class Dto
{
    [FileBetween(3, 5)]
    public SmartFile SomeFileInvalid = new ("http://example.com" ,"some_filename.txt"); // ValidationError

    [FileBetween(3, 5)]
    public string SomeFileValid = "test"; // Success
}

FileDimensions

Validates the dimensions (width and height) of an image file. Supports both exact match and range-based validation.

public class Dto
{
    [FileDimensions(128, 128)]
    public SmartFile SomeFile1;

    [FileDimensions(240, 512, 380, 720)]
    public string SomeFile2;
}

FileEncoding

Validates that the file content matches the specified character encoding. Equivalent to Laravel's 'encoding' rule (uses strict decoder validation).

public class Dto
{
    [FileEncoding("ASCII")]
    public SmartFile SomeFile;
}

FileExtension

The file under validation must have a MIME type corresponding to one of the listed extensions.

public class Dto
{
    [FileExtension("jpg", "bmp", "png")]
    public SmartFile SomeFile;
}

FileImage

The file under validation must be an image (bmp, gif, ico, jpeg, png, wbmp, webp).

public class Dto
{
    [FileImage()]
    public SmartFile SomeImageFile;
            
    [FileImage(true)]
    public SmartFile SomeSvgFile;
}

FileMax

Validates that the file size (in bytes) does not exceed the specified maximum limit.

public class Dto
{
    [FileMax(4_194_304)]
    public SmartFile SomeFile;
}

FileMime

The file under validation must match one of the given MIME types.

public class Dto
{
    [FileMime("video/avi", "video/mpeg", "video/quicktime")]
    public SmartFile SomeFile;
}

FileMin

Validates that the file size (in bytes) does not below the specified minimum limit.

public class Dto
{
    [FileMin(4_194_304)]
    public SmartFile SomeFile;
}
Product 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. 
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
0.6.0 50 10/24/2026
0.5.0 51 10/23/2026