Skip to content

Instantly share code, notes, and snippets.

@mahizsas
Created October 25, 2012 23:45
Show Gist options
  • Save mahizsas/3956194 to your computer and use it in GitHub Desktop.
Save mahizsas/3956194 to your computer and use it in GitHub Desktop.
C# - GetMimeType
static string GetMimeType(string fileName)
{
string mimeType = "application/unknown";
string ext = Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
{
mimeType = regKey.GetValue("Content Type").ToString();
}
else if (ext == ".png")
{
mimeType = "image/png";
}
return mimeType;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment