.NET 11 Preview - Get Extension From MIME Type
[C#, .NET, .NET 11 Preview, MIME]
Yesterday’s post, “.NET 11 Preview - MIME Type Lookups”, looked at how to get the MIME type of a file given its extension using the new MediaTypeMap class.
In today’s post we look at the opposite problem - how to get the extension given the MIME type.
This is also addressed using the MediaTypeMap class, via the GetExtension method.
The code is as follows:
var extension = MediaTypeMap.GetExtension("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Console.WriteLine(extension);
This will return the following:
.xlsx
In the event the MIME type is unknown, a null is returned.

TLDR
The MediaTypeMap class has a GetExtension method that gets the extension of a given MIME type.
Happy hacking!