Skip to main content
netstandard · .NET 6 · 7 · 8 · 9

Vali-FileSize

// file size utilities for .NET

6+size units
IECbinary prefix
zerodependencies
$dotnet add package Vali-FileSize

Everything you need for file size handling

Built for .NET developers who want clean, reliable and zero-dependency file size utilities.

01

Unit Conversion

Convert between any file size units: Bytes, KB, MB, GB, TB, PB, EB — with full IEC binary prefix support (KiB, MiB, GiB, TiB, PiB, EiB).

02

Smart Formatting

Format file sizes as human-readable strings with customizable decimal precision and cultural number formatting.

03

Auto Unit Detection

GetBestUnit automatically selects the most appropriate unit for any byte value, traditional or IEC.

04

Extension Methods

Ergonomic double and long extension methods — ToFormattedSize, FormatBestSize, GetBestUnit — for minimal boilerplate.

05
🔗

Dependency Injection

IValiFileSize interface for clean DI registration. Stateless singleton-safe implementation.

06

Multi-Framework

Targets netstandard2.0, netstandard2.1, net6.0, net7.0, net8.0, net9.0. Zero external dependencies.

Simple, expressive API

Auto-detect units, format sizes, convert between units — all with a clean, chainable API.

Program.cs
123456789101112
// Auto-detect best unit
var vfs = new ValiFileSize();
string result = vfs.FormatBestSize(1_500_000_000); // "1.40 GB"
// Extension methods
string formatted = 1_500_000_000.0.FormatBestSize(); // "1.40 GB"
// IEC prefixes
string iec = vfs.FormatBestSize(1_500_000_000, useIec: true); // "1.40 GiB"
// Explicit conversion
double kb = vfs.Convert(1, FileSizeUnit.Megabytes, FileSizeUnit.Kilobytes); // 1024
FM
Built byFelipe Rafael Montenegro Morriberon

.NET developer and open-source enthusiast. Creator of Vali-FileSize, Vali-Mediator and Vali-Validation.