Solved

binarywrite with PDF problem

Posted on 2001-06-05
2
780 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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