There are situations where you need to have your ASP page sending binary data to the client. As you might now, there's no direct ASP code for reading a binary file, that's why we need to use an external component for retrieving the binary file.
But instead of writing our own component, why not using the existing ones? The ADO object, which is found on any IIS web server was written to manipulate databases, and since databases are binary files, the ADO object can read our binary files...
<%
Function getBinaryFile(strFilePath)
Dim TypeBinary, oStream
TypeBinary = 1 ' Indicates a binary file
' Create the object
Set oStream = Server.CreateObject("ADODB.Stream")
' Open our file
oStream.Open
' Retreive binary data from the file
oStream.Type = TypeBinary
oStream.LoadFromFile strFilePath
' Return the binary data to the caller
getBinaryFile = oStream.read
' Destroy the ADO object
Set oStream = Nothing
End Function
Response.BinaryWrite getBinaryFile(Server.MapPath("\my_file\thefile.bin"))
%>
Comments