• گرفتن MIME type یک فایل
    #1
    Note 
    [VB]
    Public Shared Function GetMimeType(ByVal file As String) As String
    Dim mime As String = Nothing
    Dim MaxContent As Integer = CInt(New FileInfo(file).Length)
    If MaxContent > 4096 Then
    MaxContent = 4096
    End If

    Dim fs As New FileStream(file, FileMode.Open)

    Dim buf(MaxContent) As Byte
    fs.Read(buf, 0, MaxContent)
    fs.Close()
    Dim result As Integer = FindMimeFromData(IntPtr.Zero, file, buf, MaxContent, Nothing, 0, mime, 0)

    Return mime
    End Function

    <DllImport("urlmon.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function FindMimeFromData( _
    ByVal pBC As IntPtr, _
    <MarshalAs(UnmanagedType.LPWStr)> _
    ByVal pwzUrl As String, _
    <MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.I1, SizeParamIndex:=3)> ByVal _
    pBuffer As Byte(), _
    ByVal cbSize As Integer, _
    <MarshalAs(UnmanagedType.LPWStr)> _
    ByVal pwzMimeProposed As String, _
    ByVal dwMimeFlags As Integer, _
    <MarshalAs(UnmanagedType.LPWStr)> _
    ByRef ppwzMimeOut As String, _
    ByVal dwReserved As Integer) As Integer
    End Function
    [/VB]

    پاسخ
    ایجاد موضوع جدید   پاسخ به موضوع  

    موضوعات مرتبط با این موضوع...
    موضوع نویسنده پاسخ بازدید آخرین ارسال
    Note Conversion from string "" to type 'Double' is not valid NIKAN 1 538 20-02-2013 ساعت 13:23
    آخرین ارسال: VBProgrammer

    کاربرانِ درحال بازدید از این موضوع:   1 مهمان