Skip to content

Instantly share code, notes, and snippets.

@nelsonlaquet
Created May 13, 2011 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonlaquet/971294 to your computer and use it in GitHub Desktop.
Save nelsonlaquet/971294 to your computer and use it in GitHub Desktop.
public string GetMimeTypeForFile(string filename)
{
var mime = "application/octetstream";
var ext = System.IO.Path.GetExtension(filename).ToLower();
var rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (rk != null && rk.GetValue("Content Type") != null)
mime = rk.GetValue("Content Type").ToString();
return mime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment