Ultimately, we will be using the Response.BinaryWrite method to push the data back to the client. As such, we need to make sure that we pass the information in the correct format. In this case, the solitary parameter to BinaryWrite requires a type-safe byte array. This is a data type that is not supported natively in ASP, so we need to write a small component that reads a specific file and returns the data in a byte array.
Function ReadBinaryFile(ByVal sFileName As String) As Variant
Dim FileLength As Long
Dim FileNo As Long
Dim aBytes() As Byte
On Error GoTo ErrHandler
FileNo = FreeFile()
Open sFileName For Binary Access Read As #FileNo
FileLength = FileLen(sFileName)
ReDim aBytes(FileLength)
Get #FileNo, , aBytes
Close #FileNo
ReadFile = aBytes
End Function
Comments