Skip to content

Repository files navigation

MimeMapping

NugetNugetbuildcodecov

Constants for (almost) all MIME types and method to determine MIME type from a file name. Contains just over 1000 mime types.

The Dictionary is generated from the jshttp/mime-dbdb.json. Works similar to .NET's System.Web.MimeMapping.GetMimeMapping.

It aggregates data from the following sources:

The library is just a literal C# Dictionary<string, string> with over 1000 entries, and a helper method that can be passed a file path.

Example Usage

stringmyFile="myimage.jpg";stringmimeType=MimeMapping.MimeUtility.GetMimeMapping(myFile);Console.WriteLine(mimeType);// output: image/jpegstringrandomFile="data.asdf";stringmimeType=MimeMapping.MimeUtility.GetMimeMapping(randomFile);Console.WriteLine(mimeType);// output: application/octet-streamstringrawExtension="json";stringmimeType=MimeMapping.MimeUtility.GetMimeMapping(rawExtension);Console.WriteLine(mimeType);// output: application/json// List all types..foreach(varkpinMimeMapping.MimeTypes.TypeMap){Console.WriteLine($"File extension: {kp.Key}, mime string: {kp.Value}");}//Just use a constant if you already know the file type (performance)conststringmimeType=MimeMapping.KnownMimeTypes.Xlsx

About

Constants for (almost) all MIME types and file extensions, and method to determine MIME type of a file name.

Resources

Stars

83 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages