?
Solved

binarywrite with PDF problem

Posted on 2001-06-05
2
Medium Priority
?
792 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 600 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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