Send Binary Data from ASP

Page 2 of 3
  1. Introduction
  2. ReadBinaryFile Function
  3. ASP Modifications

ReadBinaryFile Function

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

You might also like...

Comments

About the author

Bruce Johnson Canada

I am the owner of a small application development consulting company that specialized in the design and implementation of Internet-based applications. While there are others who can make a web ...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon