Skip to content

Instantly share code, notes, and snippets.

@chinedudara
Forked from alex-codes/MimeTypes.cs
Created April 29, 2021 12:15
Show Gist options
  • Save chinedudara/551c42a30a475962550bc0b583dd2db7 to your computer and use it in GitHub Desktop.
Save chinedudara/551c42a30a475962550bc0b583dd2db7 to your computer and use it in GitHub Desktop.
List of common MIME types
public static class MimeTypes
{
public static string Aiff
{
get { return "audio/aiff"; }
}
public static string Avi
{
get { return "video/x-msvideo"; }
}
public static string Css
{
get { return "text/css"; }
}
public static string Csv
{
get { return "text/csv"; }
}
public static string Doc
{
get { return "application/msword"; }
}
public static string Docx
{
get { return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; }
}
public static string Dot
{
get { return "application/msword"; }
}
public static string Gif
{
get { return "image/gif"; }
}
public static string Gz
{
get { return "application/x-gzip"; }
}
public static string Htm
{
get { return System.Net.Mime.MediaTypeNames.Text.Html; }
}
public static string Html
{
get { return System.Net.Mime.MediaTypeNames.Text.Html; }
}
public static string Jpeg
{
get { return System.Net.Mime.MediaTypeNames.Image.Jpeg; }
}
public static string Jpg
{
get { return System.Net.Mime.MediaTypeNames.Image.Jpeg; }
}
public static string Js
{
get { return "application/x-javascript"; }
}
public static string Mid
{
get { return "audio/mid"; }
}
public static string Mov
{
get { return "video/quicktime"; }
}
public static string Mp3
{
get { return "audio/mpeg"; }
}
public static string Mpeg
{
get { return "video/mpeg"; }
}
public static string Mpg
{
get { return "video/mpeg"; }
}
public static string Octet
{
get { return System.Net.Mime.MediaTypeNames.Application.Octet; }
}
public static string Pdf
{
get { return System.Net.Mime.MediaTypeNames.Application.Pdf; }
}
public static string Pps
{
get { return "application/vnd.ms-powerpoint"; }
}
public static string Ppt
{
get { return "application/vnd.ms-powerpoint"; }
}
public static string Pptx
{
get { return "application/vnd.openxmlformats-officedocument.presentationml.presentation"; }
}
public static string Rtf
{
get { return System.Net.Mime.MediaTypeNames.Application.Rtf; }
}
public static string Tiff
{
get { return System.Net.Mime.MediaTypeNames.Image.Tiff; }
}
public static string Txt
{
get { return System.Net.Mime.MediaTypeNames.Text.Plain; }
}
public static string Xls
{
get { return "application/vnd.ms-excel"; }
}
public static string Xlsx
{
get { return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; }
}
public static string Xlt
{
get { return "application/vnd.ms-excel"; }
}
public static string Xml
{
get { return System.Net.Mime.MediaTypeNames.Text.Xml; }
}
public static string Zip
{
get { return System.Net.Mime.MediaTypeNames.Application.Zip; }
}
/// <summary>
/// MIME type for unknown files
/// </summary>
public static string Unknown
{
get { return "application/unknown"; }
}
/// <summary>
/// Try to determine MIME type based on the extension. If a type cannot be inferred, application/unknown will be returned
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string Auto(string fileName)
{
string mimeType = "application/unknown";
string extension = System.IO.Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension);
if (regKey != null && regKey.GetValue("Content Type") != null)
{
mimeType = regKey.GetValue("Content Type").ToString();
}
return mimeType;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment