Mime файла стандартным образом можно определить так:
[System.Runtime.InteropServices.DllImport("urlmon.dll",
CharSet = System.Runtime.InteropServices.CharSet.Unicode,
ExactSpelling = true, SetLastError = false)]
static extern int FindMimeFromData(
IntPtr pBC,
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.LPWStr)]
string pwzUrl,
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.LPArray,
ArraySubType = System.Runtime.InteropServices.UnmanagedType.I1,
SizeParamIndex = 3)]
byte[] pBuffer,
int cbSize,
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.LPWStr)]
string pwzMimeProposed,
int dwMimeFlags, out IntPtr ppwzMimeOut, int dwReserved);
public static string getMimeFromFile(byte[] fileArray)
{
IntPtr mimeout;
byte[] buf = fileArray;
int result = FindMimeFromData(IntPtr.Zero, "", buf, buf.Length, null, 0, out mimeout, 0);
if (result != 0)
throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result);
string mime = System.Runtime.InteropServices.Marshal.PtrToStringUni(mimeout);
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(mimeout);
return mime;
}