The closest thing I could find was System.Net.Mime.MediaTypeNames
but that doesn't seem to have everything (like json) since it seems to be more focused around email attachments.
An enum doesn't make much sense. MIME types are open-ended. That is, the list is not finite: new types are added from time to time.
See RFC4288: Media Type Specifications and Registration Procedures
In 2022, with .NET Core and .NET 5+, this is now available via MediaTypeNames
. For example:
MediaTypeNames.Application.Json
MediaTypeNames.Image.Png
MediaTypeNames.Text.Html
Microsoft documentation around MediaTypeNames, and each of Application, Image, Text.
- https://learn.microsoft.com/en-us/dotnet/api/system.net.mime.mediatypenames?view=net-6.0
- https://learn.microsoft.com/en-us/dotnet/api/system.net.mime.mediatypenames.application?view=net-6.0
- https://learn.microsoft.com/en-us/dotnet/api/system.net.mime.mediatypenames.image?view=net-6.0
- https://learn.microsoft.com/en-us/dotnet/api/system.net.mime.mediatypenames?view=net-6.0
- https://learn.microsoft.com/en-us/dotnet/api/system.net.mime.mediatypenames.text?view=net-6.0
Update 2013: Further MIME types have been added in .NET 8, and are much more exaustive: https://learn.microsoft.com/en-us/dotnet/api/system.net.mime.mediatypenames?view=net-8.0
text/csv
but it isn't supported. –
Perky text/csv
has been added in .NET 8, alongside a bunch of others! learn.microsoft.com/en-us/dotnet/api/… –
Memo IANA's database is most likely to be complete. Currently, they have the list available in CSV format at https://www.iana.org/assignments/media-types/application.csv
. I am assuming this is a stable URL whose content changes as updates are made. If you want to stay up to date, you'd need to put together a mechanism that is appropriate for your needs.
There is also the mime.types file that comes with Apache which seems to have been derived from the said list.
If like me you wanted to have no hard-coded string in your code you can use something like below
httpHeaders.add(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON_VALUE);
which is essentially
httpHeaders.add("Content-Type","application/json");
For my own limited purposes, I have made a static class that is basically a copy of the included .NET MediaTypeNames
class but includes the MIME types I require; .NET MediaTypeNames
is missing values I need.
public static class MediaMimeTypes
{
/// <summary>
/// Specifies that the MediaMimeType is not interpreted.
/// </summary>
public const string Octet = "application/octet-stream";
/// <summary>
/// Specifies that the MediaMimeType is in a Comma Separated Values (CSV) format.
/// </summary>
public const string Csv = "text/csv";
}
© 2022 - 2024 — McMap. All rights reserved.
System.Net.Mime.MediaTypeNames
would never be an exhaustive/complete list. – Impletion