NMimeType 1.0.2

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

NMimeType

Fast MIME type lookup for .NET applications.

The package resolves MIME types from file names, paths, or extensions using an embedded lookup table. It keeps lookups case-insensitive and indexes the table in memory so repeated reads are fast.

Why this package matters

MIME type detection shows up in file uploads, downloads, API responses, static file serving, email attachments, background processing, and storage pipelines. Getting it wrong can cause browsers to render files incorrectly, APIs to return poor metadata, or upload systems to accept files without enough classification.

This package keeps that lookup simple:

  • No operating system dependency for the MIME table.
  • No repeated JSON scanning during normal lookups.
  • Case-insensitive extension matching.
  • Works with file names, full paths, or raw extensions.
  • Supports custom embedded MIME resources for product-specific file types.
  • Targets older compatible libraries and current .NET applications.

Supported frameworks

  • netstandard2.0
  • net8.0
  • net9.0
  • net10.0

net8.0, net9.0, and net10.0 use the built-in System.Text.Json. The netstandard2.0 target references the Microsoft System.Text.Json package.

Features

  • Fast indexed lookups after the embedded table is loaded.
  • Built-in MIME table with common document, image, audio, video, archive, web, app package, and source file extensions.
  • Modern extensions such as avif, heic, wasm, webmanifest, zst, br, yaml, toml, ndjson, and geojson.
  • Get for simple lookups.
  • TryGet for unknown-safe lookups.
  • GetOrDefault for fallback MIME values.
  • Contains to check whether an extension is known.
  • GetKnownTypes to inspect the loaded table.
  • Custom embedded JSON resources with override support.

Basic usage

using MimeType;

string mimeType = Mime.Get("report.pdf");
// application/pdf

string fromExtension = Mime.Get(".json");
// application/json

string fromPath = Mime.Get("/uploads/avatar.webp");
// image/webp

Fallback values

Use GetOrDefault when your pipeline needs a real MIME type even for unknown extensions.

string mimeType = Mime.GetOrDefault("upload.unknown");
// application/octet-stream

string customFallback = Mime.GetOrDefault("upload.unknown", "application/x-custom-fallback");
// application/x-custom-fallback

TryGet and Contains

Use TryGet when an extension may be unknown and you want to avoid treating an empty string as a result.

if (Mime.TryGet("video.webm", out var mimeType))
{
    Console.WriteLine(mimeType);
}

bool supported = Mime.Contains("archive.zst");

Instance API

IMime mime = new Mime();

string value = mime["document.docx"];
string sameValue = mime.Get("document.docx");

List known types

IReadOnlyDictionary<string, string> knownTypes = Mime.GetKnownTypes();

foreach (var item in knownTypes)
{
    Console.WriteLine($"{item.Key}: {item.Value}");
}

Custom MIME resources

You can add your own embedded JSON resources. Custom resources override the built-in table when the same extension appears in both.

Example JSON:

{
  "custom": "application/x-custom",
  "pdf": "application/pdf"
}

Marker type:

using MimeType;

[MimeTypeResourceName("Content")]
public class MyMimeTypes
{
}

Register the resource:

Mime.AddMimeResources(typeof(MyMimeTypes));

The JSON file should be embedded in the same assembly as the marker type. The attribute value should match the namespace or folder segment used in the embedded resource name.

Build

dotnet build MimeType.sln

Release package

The repository includes a GitHub Actions workflow that creates and publishes the NuGet package when a GitHub Release is published.

Before publishing a release, add this repository secret in GitHub:

  • NUGET_API_KEY: an API key from nuget.org with permission to push this package.

Release flow:

  1. Create a tag such as v1.0.0.
  2. Create and publish a GitHub Release for that tag.
  3. The workflow builds the solution, packs NMimeType, uploads the .nupkg as a workflow artifact, and pushes it to nuget.org.

The package version is taken from the release tag. For example, v1.0.0 publishes package version 1.0.0.

Notes

  • Extension lookup is case-insensitive.
  • File names and paths are supported; the last extension is used.
  • Unknown extensions return string.Empty from Mime.Get.
  • Prefer Mime.TryGet or Mime.GetOrDefault when unknown extensions are expected.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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
1.0.2 112 7/5/2026
1.0.1 224 7/5/2026
1.0.0 1,299 7/9/2020