![]() |
VOOZH | about |
dotnet add package FileSignatures --version 7.2.1
NuGet\Install-Package FileSignatures -Version 7.2.1
<PackageReference Include="FileSignatures" Version="7.2.1" />
<PackageVersion Include="FileSignatures" Version="7.2.1" />Directory.Packages.props
<PackageReference Include="FileSignatures" />Project file
paket add FileSignatures --version 7.2.1
#r "nuget: FileSignatures, 7.2.1"
#:package FileSignatures@7.2.1
#addin nuget:?package=FileSignatures&version=7.2.1Install as a Cake Addin
#tool nuget:?package=FileSignatures&version=7.2.1Install as a Cake Tool
A small library for detecting the type of a file based on header signature (also known as magic number) rather than file extension. It is designed with extensibility in mind, so that recognised formats can be added easily.
FileSignatures is available on NuGet, so can be installed via the Package Manager:
Install-Package FileSignatures
Create an instance of the FileFormatInspector class, then pass it a stream to your file:
var inspector = new FileFormatInspector();
var format = inspector.DetermineFileFormat(stream);
This will return a FileFormat instance which contains the signature and media type of the recognised format, or null if a matching format could not be determined.
You can either register an instance calling the empty constructor which will register all formats in the FileSignatures assembly:
services.AddSingleton<IFileFormatInspector>(new FileFormatInspector());
Or use FileFormatLocator to scan for the formats you are interested in then pass that to the constructor of FileFormatInspector and register that instance:
var recognised = FileFormatLocator.GetFormats().OfType<Image>();
var inspector = new FileFormatInspector(recognised);
services.AddSingleton<IFileFormatInspector>(inspector);
In this example, only formats which derive from Image (jpg, tiff, bmp, etc.) will be detected. Anything else will be ignored.
Because the formats are defined as a type hierarchy, you can either check for a specific type if you want to work with a particular format, or the base type if you are interested in multiple formats.
var format = inspector.DetermineFileFormat(stream);
if(format is Pdf) {
// Just matches Pdf
}
if(format is OfficeOpenXml) {
// Matches Word, Excel, Powerpoint
}
if(format is Image) {
// Matches any image format
}
See the examples for a sample web application and a console application which demonstrate how to filter uploads by a particular format and retrieve the signature details for a file.
Currently, the following formats are built-in:
| Name | Media-Type | Extension |
|---|---|---|
| 3GPP | video/3gpp | .3gp |
| Bitmap | image/bmp | .bmp |
| Excel | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | .xlsx |
| Excel 97-2003 | application/vnd.ms-excel | .xls |
| Exe (Windows) | application/octet-stream | .exe |
| GIF | image/gif | .gif |
| JPEG | image/jpeg | .jpg |
| MP4 | video/mp4 | .mp4 |
| Open Document Presentation | application/vnd.oasis.opendocument.presentationn | .odp |
| Open Document Spreadhseet | application/vnd.oasis.opendocument.spreadsheet | .ods |
| Open Document Text | application/vnd.oasis.opendocument.text | .odt |
| Outlook Message | application/vnd.ms-outlook | .msg |
| application/pdf | ||
| PNG | image/png | .png |
| PowerPoint | application/vnd.openxmlformats-officedocument.presentationml.presentation | .pptx |
| Powerpoint 97-2003 | application/vnd.ms-powerpoint | .ppt |
| QuickTime | video/quicktime | .mov |
| Rich Text Format | application/rtf | .rtf |
| TIFF | image/tiff | .tif |
| Visio | application/vnd.visio | .vsdx |
| Visio 97-2003 | application/vnd.visio | .vsd |
| Webp | image/webp | .webp |
| Word | application/vnd.openxmlformats-officedocument.wordprocessingml.document | .docx |
| Word template | application/vnd.openxmlformats-officedocument.wordprocessingml.template | .dotx |
| Word 97-2003 | application/msword | .doc |
| Xps | application/vnd.ms-xpsdocument | .xps |
| Zip | application/zip | .zip |
Create a new class (or many classes) which inherit from FileFormat to implement a custom format. Next, pass a collection of recognised formats to the constructor of FileFormatInspector, being sure to include your custom format.
The FileFormatLocator class can be used to load all custom formats located within an assembly:
var assembly = typeof(CustomFileFormat).GetTypeInfo().Assembly;
// Just the formats defined in the assembly containing CustomFileFormat
var customFormats = FileFormatLocator.GetFormats(assembly);
// Formats defined in the assembly and all the defaults
var allFormats = FileFormatLocator.GetFormats(assembly, true);
Using this method, you can continue to create custom formats and they will automatically be included into the recognised formats without any additional configuration.
This project is licensed under the .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on FileSignatures:
| Package | Downloads |
|---|---|
|
HanaTech.Framework.MvcFunction
Package Description |
|
|
Util.FileStorage
Util.FileStorage是Util应用框架文件存储操作基础类库 |
|
|
Toxy
Toxy is a .NET library for extracting data from various document formats |
|
|
Articulate
A wonderful Blog engine built on Umbraco |
|
|
ThePensionsRegulator.GovUk.Frontend
Based on the GOV.UK Design System and GovUk.Frontend.AspNetCore. Adds extra features and components. |
Showing the top 3 popular GitHub repositories that depend on FileSignatures:
| Repository | Stars |
|---|---|
|
dotnetcore/Util
Util是一个.Net平台下的应用框架,旨在提升中小团队的开发能力,由工具类、分层架构基类、Ui组件,配套代码生成模板,权限等组成。
|
|
|
nissl-lab/toxy
.net text extraction & export framework
|
|
|
Shazwazza/Articulate
A wonderful Blog engine built on Umbraco
|
| Version | Downloads | Last Updated |
|---|---|---|
| 7.2.1 | 34,842 | 5/20/2026 |
| 7.2.0 | 14,696 | 5/7/2026 |
| 7.1.0 | 38,979 | 4/24/2026 |
| 7.0.0 | 104,850 | 2/25/2026 |
| 6.1.1 | 371,931 | 9/30/2025 |
| 6.1.0 | 36,058 | 9/7/2025 |
| 6.0.0 | 51,864 | 8/1/2025 |
| 5.3.0 | 17,453 | 7/29/2025 |
| 5.2.0 | 183,571 | 5/21/2025 |
| 5.2.0-rc1 | 284 | 5/20/2025 |
| 5.1.1 | 368,516 | 11/29/2024 |
| 5.1.1-rc3 | 247 | 11/27/2024 |
| 5.1.1-rc2 | 269 | 11/26/2024 |
| 5.1.0 | 288,284 | 9/13/2024 |
| 5.0.2 | 328,240 | 6/22/2024 |
| 5.0.1 | 70,900 | 5/29/2024 |
| 4.4.1 | 743,801 | 10/4/2023 |