| HOWTO: Read and Display Binary Data in ASPID: Q193998 
 | 
This article shows how to read and display binary data using Active Server
Pages.
Many developers appreciate the ease of using the Scripting.FileSystemObject
to open an ASCII file and then display its contents in Microsoft Word or
Microsoft Excel from within Internet Explorer. In its current inception,
ASP does not directly provide any comparable objects to read files that
contain binary data such as an Excel worksheet with macros, an Adobe
Acrobat (.pdf) file, a .gif image, or any other files that contain binary
data. However, an ASP developer can write a custom business object or
component that adds this functionality.
Part I provides the ASP code that receives and then displays the binary file using an appropriate MIME type, and Part II shows how to create the Visual Basic 5.0 (or later) ActiveX DLL component that extends the capability of ASP to read binary data.
   <%
   Response.buffer = TRUE
   Response.ContentType = "application/x-msexcel"
   Dim vntStream
   Set oMyObject = Server.CreateObject("MyObject.BinRead")
   vntStream = oMyObject.readBinFile("c:\temp\tempxls.xls")
   Response.BinaryWrite(vntStream)
   Set oMyObject = Nothing
   Response.End
   %> 
   Function readBinFile(ByVal bfilename As String)
       Dim fl As Long
       Dim binbyte() As Byte
       Dim binfilestr As String
       On Error GoTo errHandler
       Open bfilename For Binary Access Read As #1
       fl = FileLen(bfilename)
       ReDim binbyte(fl)
       Get #1, , binbyte
       Close #1
       readBinFile = binbyte
       Exit Function
   errHandler:
       Exit Function
   End Function Additional query words:
Keywords          : kbcode kbASP100 kbASP400 kbCOMt kbScript kbVBp500 kbVBp600 kbVisID100 kbVisID600 kbGrpASP 
Version           : WINDOWS:1.0,6.0; winnt:1.0,4.0
Platform          : WINDOWS winnt 
Issue type        : kbhowto Last Reviewed: May 27, 1999