Showing posts with label MimeType. Show all posts
Showing posts with label MimeType. Show all posts

Saturday, October 29, 2011

Getting Mimetype .NET


Private Function MimeType(Filename As String) As String
 Dim mime As String = "application/octetstream"
 Dim ext As String = System.IO.Path.GetExtension(Filename).ToLower()
 Dim rk As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext)
 If rk IsNot Nothing AndAlso rk.GetValue("Content Type") IsNot Nothing Then
  mime = rk.GetValue("Content Type").ToString()
 End If
 Return mime
End Function
In short - you just feed it with path top a file - and get back the mime type. Ex MimeType("f:\\theimage.jpg") --->>> "image/jpeg"