Solved

binarywrite with PDF problem

Posted on 2001-06-05
2
777 Views
Last Modified: 2007-11-27
I am trying to binarywrite a PDF file to the browser.  No matter what I try, I just get the binary data in the browser, instead of acrobat opening.  Please look at this code and tell me if you can find any problems.  Thanks..

---- ASP
     Set objBinFile = Server.CreateObject("ASPBinFile.clsASPBinFile")
     mFile = rsinvoice("filename")
     mStream = objBinFile.BinFileRead(mFile)
     response.buffer=true
'      Response.CacheControl = "public"
'     response.expires = 0
     Response.contenttype = "application/pdf"
     Response.AddHeader "Content-Disposition", "inline;filename=invoice.pdf"
'     Response.Addheader "Content-Length", LenB(mstream)
     Response.binarywrite mstream
     response.end()
     response.flush
     Set objBinFile = Nothing
else
     response.write "DOH!"
end if

---- objBinFile.BinFileRead()
Option Explicit


Function BinFileRead(ByVal inFileSpec As String) As Variant
     On Error GoTo errHandler
     Dim mHandle
     Dim lngFileLen As Long
     Dim arrData() As Byte
       
     mHandle = FreeFile
     Open inFileSpec For Binary Access Read As #mHandle

     lngFileLen = FileLen(inFileSpec)
     ReDim arrData(lngFileLen)

     Get #mHandle, , arrData
     Close #mHandle
       
     BinFileRead = arrData
     Exit Function

errHandler:
End Function
0
Comment
Question by:tranqy
2 Comments
 

Accepted Solution

by:
Chesty earned 200 total points
ID: 6157483
Are you including the <html> and <head> tags like you would for an ordinary web page? Don't. It makes the browser expect a web page.

If your asp page is called "invoice.asp" it must be..

<%
Set ObjBinFile....
.
.
.
Set ObjBinFile=Nothing
Response.End
%>

You can't put response.write statements in either because you have told the browser it is "application/pdf". Link to "invoice.asp" as you would any other file for download and it should work.
0
 

Author Comment

by:tranqy
ID: 6159274
I worked with this page forever, and all I had to do was pull out the html tags.  ARGH.  Thank you very much for your insight.  Your answer fixed my problem!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP Classic - Load test 2 53
Choose the older file FSO 6 50
msxml3.dll error '80072efd' A connection with the server could be not established 8 44
ASP exit 10 19
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question