Добавить комментарий - CodeHelper

Добавить комментарий

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;
 }
Внимание! Вы собираетесь отправить информацию от имени анонимного пользователя.
v1.7.123.556
© 2009—2010 CodeHelper FAQ | О сайте | Обратная связь | История изменений | Статьи
Creative Commons LicenseМатериалы сайта распространяются под лицензией Creative Commons Attribution-Share Alike 3.0 Unported.