How to get the Content Type(MimeType) of a file C#

private string MimeType (string Filename)
{
string mime = “application/octetstream”;
string ext = System.IO.Path.GetExtension(Filename).ToLower();
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (rk != null && rk.GetValue(“Content Type”) != null)
mime = rk.GetValue(“Content Type”).ToString();
return mime;
}

~ di Merlino su Gennaio 9, 2008.

4 Risposte to “How to get the Content Type(MimeType) of a file C#”

  1. It’s work!

  2. Thanks!!!!!!
    I have used your solution in my project with flash upload :D .

    THANKS!!

  3. [...] getMimeTypeFromExtension Hi Alhambra, That’s it http://petrocel.wordpress.com/2008/0…e-of-a-file-c/ > Hi misters, > > In Java there is the MimeType.getMimeTypeFromExtension function. > [...]

  4. Thanks It Works

Lascia un commento