简体中文:README.CN.md
正體中文:README.TW.md
Provides a huge two-way mapping of file extensions to mime types and mime types to file extensions, e.g.:
...
{".jpe", "image/jpeg"},
{".jpeg", "image/jpeg"},
{".jpg", "image/jpeg"},
{".js", "application/javascript"},
{".json", "application/json"},
...
There is a little different behavior between samuelneff version.
In my experience, one extension sometimes will have different mime type depend on various browser.
This package will return all match mime.
For example: .mp3
and zip
will have multi mime type depend on various browser, see: https://stackoverflow.com/a/28021591/1799047
, .zip
will have three mime type: application/zip, application/octet-stream, application/x-zip-compressed
A NuGet package is available for easy integration into VisualStudio and automatic updates. Alternatively, you can clone and reference or copy the class to your project.
Install-Package MimeTypeMap.List
Support .NET 4.5 above or .NET Standard 1.0 above
After installation MimeTypeMap.List, include the following using statement in your class:
using MimeTypeMap.List;
Console.WriteLine("txt -> " + MimeTypeMap.GetMimeType("txt")); // "text/plain"
Pass in a string extension and get a mime type back. Optionally include the period. If not it will be added before looking up the mime type.
If no mime type is found then the generic "application/octet-stream" is returned.
Console.WriteLine("audio/wav -> " + MimeTypeMap.GetExtension("audio/wav")); // ".wav, .wave"
Pass in a mime type and get an extension back. If the mime type is not registered, an error is thrown.
see the example project and try for yourself
Please submit pull requests for any additions. Thanks!