sending pdf content to the browser

G

Guest

I have pdf files stored in a database image field. I need an aspx page that
will send the pdf to the browser. The code I have (in the page_load event)
works the first time I run it:

[code to query database and put pdf contents into bytearray ba, with length
K omitted]
Response.ContentType = "application/pdf"
Response.Clear()
Response.OutputStream.Write(ba, 0, K)
Response.End()

The first time I run the page, I see the pdf in the browser, as I wish. When
I refresh the page (or change the querystring parameter), I get a white blank
screen in my web browser. I don't know what the browser is doing (IE 6.0).
If I right-click the browser screen and select "View Source", I get a message
from IE "The XML source file is unavailable for viewing".

I also get the following message in the Immediate Window when the
Response.End is executed: "A first chance exception of type
'System.Threading.ThreadAbortException' occurred in mscorlib.dll. An
exception of type 'System.Threading.ThreadAbortException' occurred in
mscorlib.dll but was not handled in user code".

Any clues as how to debug this? Someone else wrote that the above error can
be ignored because it is always generated on Response.End. Is that true? I
don't think this is a caching problem because if I put a debug breakpoint in
the page_load event, the code appears to execute correctly (until it gets to
the response.end).

Joel
 
G

Guest

Thanks for the reply, but it didn't help.

Greg Young said:
Try Response.Flush() before Response.End

Cheers,

Greg
Joel H said:
I have pdf files stored in a database image field. I need an aspx page
that
will send the pdf to the browser. The code I have (in the page_load
event)
works the first time I run it:

[code to query database and put pdf contents into bytearray ba, with
length
K omitted]
Response.ContentType = "application/pdf"
Response.Clear()
Response.OutputStream.Write(ba, 0, K)
Response.End()

The first time I run the page, I see the pdf in the browser, as I wish.
When
I refresh the page (or change the querystring parameter), I get a white
blank
screen in my web browser. I don't know what the browser is doing (IE
6.0).
If I right-click the browser screen and select "View Source", I get a
message
from IE "The XML source file is unavailable for viewing".

I also get the following message in the Immediate Window when the
Response.End is executed: "A first chance exception of type
'System.Threading.ThreadAbortException' occurred in mscorlib.dll. An
exception of type 'System.Threading.ThreadAbortException' occurred in
mscorlib.dll but was not handled in user code".

Any clues as how to debug this? Someone else wrote that the above error
can
be ignored because it is always generated on Response.End. Is that true?
I
don't think this is a caching problem because if I put a debug breakpoint
in
the page_load event, the code appears to execute correctly (until it gets
to
the response.end).

Joel
 
G

Guest

I think I found a workaround. According to this page:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=129441&SiteID=1
Installation of Visual Studio causes the problem. If I simply add another
parameter to the querystring like "&dummy=x.pdf", the problem disappears.

Joel

Joel H said:
Thanks for the reply, but it didn't help.

Greg Young said:
Try Response.Flush() before Response.End

Cheers,

Greg
Joel H said:
I have pdf files stored in a database image field. I need an aspx page
that
will send the pdf to the browser. The code I have (in the page_load
event)
works the first time I run it:

[code to query database and put pdf contents into bytearray ba, with
length
K omitted]
Response.ContentType = "application/pdf"
Response.Clear()
Response.OutputStream.Write(ba, 0, K)
Response.End()

The first time I run the page, I see the pdf in the browser, as I wish.
When
I refresh the page (or change the querystring parameter), I get a white
blank
screen in my web browser. I don't know what the browser is doing (IE
6.0).
If I right-click the browser screen and select "View Source", I get a
message
from IE "The XML source file is unavailable for viewing".

I also get the following message in the Immediate Window when the
Response.End is executed: "A first chance exception of type
'System.Threading.ThreadAbortException' occurred in mscorlib.dll. An
exception of type 'System.Threading.ThreadAbortException' occurred in
mscorlib.dll but was not handled in user code".

Any clues as how to debug this? Someone else wrote that the above error
can
be ignored because it is always generated on Response.End. Is that true?
I
don't think this is a caching problem because if I put a debug breakpoint
in
the page_load event, the code appears to execute correctly (until it gets
to
the response.end).

Joel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top