Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find file's type
Message
 
 
À
27/02/2017 11:17:20
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01648574
Message ID:
01648576
Vues:
21
Hi Michel,

What does this syntax do? (Last {})
' Get the byte-order mark, if there is one
				loByte = New Byte(lnByteToRead) {}
Also, do you have other types - I am interested in PDF, DOCX and Excel too?

Thanks again.

>>I am wondering if someone has a routine to figure out file's type based on either its content or its filename. In my routine I have
>
>This is reading binary signature. Here is an example:
>
>
>		Try
>
>            ' Get it into a stream
>            loFile = New FileStream(lcFile, FileMode.Open, FileAccess.Read, FileShare.Read)
>
>            ' If we can work with the file
>            If loFile.CanSeek Then
>
>				' Initialization
>				lnLength = loFile.Length
>
>				' Number of bytes to read
>				lnByteToRead = 2048
>
>				' Maximum number of bytes to read
>				If lnLength < 2048 Then
>					lnByteToRead = lnLength
>				End If
>
>				' Get the byte-order mark, if there is one
>				loByte = New Byte(lnByteToRead) {}
>
>				loFile.Read(loByte, 0, lnByteToRead - 1)
>			Else
>				cMessage = cUnableToReadTheFile
>				Clear()
>				Return False
>			End If
>
>			' Close the file
>			loFile.Close()
>
>		Catch loError As Exception
>
>            ' If we log the error
>            If lLogError Then
>
>                ' Get the proper definition as per the current scope
>                If oProcess Is Nothing Then
>					oApp.ErrorSetup(loError)
>				Else
>					oProcess.ErrorSetup(loError)
>				End If
>
>			End If
>
>			cMessage = loError.Message
>			Clear()
>			Return False
>		End Try
>
>		' Initialization
>		lcString = Encoding.Default.GetString(loByte)
>
>		' If we have less than four characters
>		If lcString.Length < 4 Then
>			cMessage = cNotEnoughCharacter
>			Clear()
>			Return False
>		End If
>
>		' If this is a JPG
>		If Mid(lcString, 1, 3) = Chr(255) + Chr(216) + Chr(255) Then
>			cExtension = "JPG"
>			nNoFileType = 6
>			Clear()
>			Return True
>		End If
>
>		' If this is a GIF
>		If Mid(lcString, 1, 3) = "GIF" Then
>			cExtension = "GIF"
>			nNoFileType = 7
>			Clear()
>			Return True
>		End If
>
>		' If this is a EMF
>		If Mid(lcString, 42, 3) = "EMF" Then
>			cExtension = "EMF"
>			nNoFileType = 13
>			Clear()
>			Return True
>		End If
>
>		' If this is a WMF
>		If Mid(lcString, 1, 4) = Chr(215) + Chr(205) + Chr(198) + Chr(154) Then
>			cExtension = "WMF"
>			nNoFileType = 14
>			Clear()
>			Return True
>		End If
>
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform