Function CheckForJpegs(ByVal sFile As String) As Boolean
'Author - Abhijit
'Date - 19-July-2005
'Purpose - Check if the given image file is a jpeg file or not.
'Assumption - The image file exists in the given location.
Dim strFileStream As FileStream
Dim binRead As BinaryReader
Dim iByteCounter As Integer
Dim strTemp As String
iByteCounter = 0
strFileStream = New FileStream(sFile, FileMode.Open)
binRead = New BinaryReader(strFileStream)
Dim fileByte() As Byte = binRead.ReadBytes(11)
strFileStream.Close()
For iByteCounter = 0 To 5
strTemp = strTemp & Hex((fileByte(iByteCounter)))
Next iByteCounter
For iByteCounter = 6 To 10
strTemp = strTemp & ChrW((fileByte(iByteCounter)))
Next iByteCounter
If InStr(strTemp, "JFIF", CompareMethod.Text) Then
CheckForJpegs = True
ElseIf strTemp.Substring(0, 5) = "FFD8FF" Then 'This test is required for files created on Mac / older versions on PC
CheckForJpegs = True
Else
CheckForJpegs = False
End If
End Function