' 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?
> 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 >