KingJosh
asked on
Response.ContentType = "application/pdf"
I am trying to display a PDF file (which I am being passed from a web service as a binary stream) in a browser, but I am being prompted to save the file instead. I don't want the user to be prompted; I just want the PDF to be displayed. Here is the code:
Dim binaryData() As Byte
binarydata = GetDataHere()
Response.ContentType = "application/pdf"
Response.BinaryWrite(binar yData)
Response.End()
I also tried adding Response.Flush() and Response.Close() just for good measure, but it didn't help.
I'm using ASP.NET. Any ideas?
Dim binaryData() As Byte
binarydata = GetDataHere()
Response.ContentType = "application/pdf"
Response.BinaryWrite(binar
Response.End()
I also tried adding Response.Flush() and Response.Close() just for good measure, but it didn't help.
I'm using ASP.NET. Any ideas?
ASKER
I tried both commenting out that line and replacing it but both times I was prompted to save the file. Does it make a difference that GetDataHere returns a regular STRING, which I then convert (using System.Convert.FromBase64S tring)? When I write out the converted bytes to a file then response.redirect to that file it works fine...I just don't want to have to write out the file every time...
try this,
Dim binaryData() As Byte
binarydata = GetDataHere()
Response.ContentType = "application/pdf"
Response.OutputStream.Writ e(binaryDa ta, 0, FileSize)
Response.BinaryWrite(binar yData)
Response.End()
HTH
Henry
Dim binaryData() As Byte
binarydata = GetDataHere()
Response.ContentType = "application/pdf"
Response.OutputStream.Writ
Response.BinaryWrite(binar
Response.End()
HTH
Henry
ASKER
Same results...I added the code:
Response.ContentType = "application/pdf"
Response.OutputStream.Writ e(binaryDa ta, 0, binaryData.Length)
Response.BinaryWrite(binar yData)
Response.End()
(I used binarydata.length for the file size)
First it choked on the Response.End ("Thread was being aborted."), but now it's just prompting me to save the results...
Response.ContentType = "application/pdf"
Response.OutputStream.Writ
Response.BinaryWrite(binar
Response.End()
(I used binarydata.length for the file size)
First it choked on the Response.End ("Thread was being aborted."), but now it's just prompting me to save the results...
oops.. I forgot something..
remove this line,
Response.BinaryWrite(binar yData)
it should works, I have tested it.
remove this line,
Response.BinaryWrite(binar
it should works, I have tested it.
ASKER
Sorry...Still getting the prompt. It's weird...When I take that binaryData and convert it into a regular string, then create a file on the server, I can response.redirect to it with no problem...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you are still having the same problem after using the code from my previous comment, can you post more code here?
ASKER
I don't understand what the difference is, but it works now! Thanks - J
ASKER
I'm having a new problem with this...If anyone wants a quick 250 points, see question Q_21106095.html.
Dear? Sir:
You post to refer an question (Q_21106095.html.) which exists no anymore. Prehaps, made deleted??!@?
As I am,
Vikläs
You post to refer an question (Q_21106095.html.) which exists no anymore. Prehaps, made deleted??!@?
As I am,
Vikläs
ASKER
That is correct, ESH. I had problems posting the question (it wasn't showing up in the searches, etc." so I deleted it. I think there's an issue with the length of the question being posted...Thank you anyway for your interest.
I really need to do that same thing in COLD FUSION CFM if you have any help for me....
https://www.experts-exchange.com/questions/21113411/save-a-PDF-file-submitted-from-adobe-reader-to-cfm.html
ASKER
Sorry...I never used Cold Fusion...
how do you do this in the old ASP or in VB 6?
ASKER
The accepted answer should work for ASP as well.
It could be because of the Response.ContentType = "application/pdf". Try commenting that out or changing it to text/html.
Regards,
Zyloch