In urlmon.dll,there’s a function called FindMimeFromData.
Read the first(up to) 256 bytes from the file and pass it to FindMimeFromData function.
Sample code:
In C# how to find the mime type of a file_.netusing System.Runtime.InteropServices;    
In C# how to find the mime type of a file_.net
In C# how to find the mime type of a file_.net
In C# how to find the mime type of a file_.net[DllImport(@"urlmon.dll", CharSet = CharSet.Auto)]    
In C# how to find the mime type of a file_.netprivate extern static System.UInt32 FindMimeFromData(    
In C# how to find the mime type of a file_.netSystem.UInt32 pBC,    
In C# how to find the mime type of a file_.net[MarshalAs(UnmanagedType.LPStr)] System.String pwzUrl,    
In C# how to find the mime type of a file_.net[MarshalAs(UnmanagedType.LPArray)] byte[] pBuffer,    
In C# how to find the mime type of a file_.netSystem.UInt32 cbSize,    
In C# how to find the mime type of a file_.net[MarshalAs(UnmanagedType.LPStr)] System.String pwzMimeProposed,    
In C# how to find the mime type of a file_.netSystem.UInt32 dwMimeFlags,    
In C# how to find the mime type of a file_.netout System.UInt32 ppwzMimeOut,    
In C# how to find the mime type of a file_.netSystem.UInt32 dwReserverd    
In C# how to find the mime type of a file_.net);    
In C# how to find the mime type of a file_.netpublic string getMimeFromFile(string filename)    
In C# how to find the mime type of a file_.net{    
In C# how to find the mime type of a file_.netif (!File.Exists(filename))    
In C# how to find the mime type of a file_.netthrow new FileNotFoundException(filename + " not found");    
In C# how to find the mime type of a file_.netbyte[] buffer = new byte[256];    
In C# how to find the mime type of a file_.netusing (FileStream fs = new FileStream(filename, FileMode.Open))    
In C# how to find the mime type of a file_.net{    
In C# how to find the mime type of a file_.netif (fs.Length >= 256)    
In C# how to find the mime type of a file_.net                                fs.Read(buffer, 0, 256);    
In C# how to find the mime type of a file_.netelse    
In C# how to find the mime type of a file_.net                                fs.Read(buffer, 0, (int)fs.Length);    
In C# how to find the mime type of a file_.net}    
In C# how to find the mime type of a file_.nettry    
In C# how to find the mime type of a file_.net{    
In C# how to find the mime type of a file_.netSystem.UInt32 mimetype;    
In C# how to find the mime type of a file_.netFindMimeFromData(0, null, buffer, 256, null, 0, out mimetype, 0);    
In C# how to find the mime type of a file_.netSystem.IntPtr mimeTypePtr = new IntPtr(mimetype);    
In C# how to find the mime type of a file_.netstring mime = Marshal.PtrToStringUni(mimeTypePtr);    
In C# how to find the mime type of a file_.netMarshal.FreeCoTaskMem(mimeTypePtr);    
In C# how to find the mime type of a file_.netreturn mime;    
In C# how to find the mime type of a file_.net}    
In C# how to find the mime type of a file_.netcatch (Exception e)    
In C# how to find the mime type of a file_.net{    
In C# how to find the mime type of a file_.netreturn "unknown/unknown";    
In C# how to find the mime type of a file_.net}    
In C# how to find the mime type of a file_.net}    
In C# how to find the mime type of a file_.net
注意:文件的大小必须大于256字节。