Content feed Comments Feed

The Official ASATO Site

Hi, welcome to my blog. ASP,asp.net,Health,Javascript,JQUERY

How to get mimetype Windows

Posted by admin On April - 28 - 2010

What are MIME types?
Similar to file extensions but more universally accepted, “MIME types” are used to identify the type of information that a file contains. While the file extension .html is informally understood to mean that the file is an HTML page, there is no requirement that it mean this, and many HTML pages have different file extensions.
Here are some examples of common mime types seen on the web:
Type Common                 File Extension              Purpose
text/html             .html                Web Page
image/png          .png                   PNG-format image
image/jpeg         .jpeg                  JPEG-format image
audio/mpeg       .mp3                 MPEG AudioFile

How to get mimetypes?
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;
}

Note:
This function needs permission to read from registry – so it might not be suited in a web scenario.

Comments are closed.