Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detecting file type
Message
 
À
14/02/2009 03:04:36
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Web
Divers
Thread ID:
01381670
Message ID:
01381733
Vues:
22
This message has been marked as a message which has helped to the initial question of the thread.
Last year, I had to ensure that a file was really a PDF and I used found that the first 4 characters of the first line where %PDF-


>This revised version seems to work ok with some additional type. I also adjusted the code to go in binary.
>
>
>        ' Return the file type
>        ' expC1 File name with the full path
>        Public Function FileType(ByVal tcFile As String) As String
>            Dim lcString As String = ""
>            lcString = FileToStrBinary(tcFile)
>
>            If lcString.Length < 4 Then
>                Return ""
>            End If
>
>            If Left(lcString, 3) = Chr(255) + Chr(216) + Chr(255) Then
>                Return "JPG"
>            End If
>
>            If Left(lcString, 3) = "GIF" Then
>                Return "GIF"
>            End If
>
>            If Mid(lcString, 42, 3) = "EMF" Then
>                Return "EMF"
>            End If
>
>            If Left(lcString, 4) = Chr(215) + Chr(205) + Chr(198) + Chr(154) Then
>                Return "WMF"
>            End If
>
>            If Left(lcString, 4) = Chr(77) + Chr(77) + Chr(0) + Chr(42) Then
>                Return "TIF"
>            End If
>
>            If Left(lcString, 4) = Chr(137) + "PNG" Then
>                Return "PNG"
>            End If
>
>            If Left(lcString, 2) = "BM" Then
>                Return "BMP"
>            End If
>
>            If Left(lcString, 3) = "CWS" And Asc(Mid(lcString, 4, 1)) < 16 Then
>                Return "SWF"
>            End If
>
>            If Left(lcString, 3) = "FWS" And Asc(Mid(lcString, 4, 1)) < 16 Then
>                Return "SWF"
>            End If
>
>            If Left(lcString, 4) = "PK" + Chr(3) + Chr(4) Then
>                Return "ZIP"
>            End If
>
>            If UCase(Left(lcString, 6)) = "<?XML " Then
>                Return "XML"
>            End If
>
>            If Left(lcString, 8) = Chr(208) + Chr(207) + Chr(17) + Chr(224) + _
>             Chr(161) + Chr(177) + Chr(26) + Chr(225) Then
>                Return "DOC"
>            End If
>
>            Return ""
>        End Function
>
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform