summary
This article describes how to read and display binary data using the Active Server Pages (Dynamic Server Page).
Many developers appreciate the convenience of the ASCII file from Internet Explorer to open the ASCII file in Microsoft Word or Microsoft Excel. But at present, the ASP does not provide any similar objects to read files containing binary data, such as a macro's Excel worksheet, Adobe Acrobat (.pdf) file, .gif image, or any other file containing binary data. . However, ASP developers can write a custom business object or component that adds this feature.
More information
"Part I" provides an ASP code that receives and then uses the appropriate MIME type to display binary files, "Part II" shows how to create a Visual Basic 5.0 (or updated) ActiveX DLL component to extend the ability of ASP to read binary data. .
Part I: Open an ASP example of an Excel worksheet with macro
<%
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
%>
Note: For the Acrobat file, use the response.contettype = "Application / PDF" to change the MIME type. For .gif images, use response.contenttype = "image / gif".
Part II: Visual Basic 5.0 ActiveX DLL (MyObject.binread)
To create components that perform binary reading features, perform the following steps:
Create a new ActiveX DLL project in the Visual Basic 5.0 or updated version.
Rename this item as MyObject.
Rename the class module to binread.
Cut the following code and paste the "General Declarations" section of the class module:
Function Readbinfile (Byval BfileName As String) AS Variant
DIM FL AS Long
DIM FILENUM AS Long
Dim binbyte () as Byte
DIM BINFILESTR AS STRING
ON Error Goto Errhandler
FILENUM = Freefile
Open bfilename for binary access # #filenum
FL = filelen (bfilename)
Redim Binbyte (FL)
Get #filenum,, binbyte
Close #filenum
Readbinfile = Binbyte
EXIT FUNCTION
Errhandler:
EXIT FUNCTION
END FUNCTION
Save the project.
Click "Make MyObject.dll" in the File menu.
If the web server is different from the computer where you created this component, you will need to copy this component to the web server and register it with Regsvr32. To merge the files created in "Part I" to another ASP page with text or other format, use the server side to include the statement.
The information in this article applies to:
Microsoft Visual Basic Professional Edition for Windows 5.0
Microsoft Visual Basic Professional Edition for Windows 6.0
Microsoft Visual Basic Enterprise Edition for Windows 5.0
Microsoft Visual Basic Enterprise Edition for Windows 6.0
Microsoft Active Server Pages