Hi
I have a vb.net app that is required to open a pdf when the user clicks a link in a gridview..
The handler in the rowCommand event for the gridview fires, but I can't get the pdf to actually open...
This one is driving me nuts....
Error = "The thread was being aborted"
If I comment out the "Response.end()" there's no error, but no document opening either...
Here's the relavent code snippet....
Try Dim client As New WebClient() Dim buffer As [Byte]() = client.DownloadData(strFileName) Dim fileName As String = "EmploymentContract.pdf" Response.Buffer = True Response.Clear() Response.ContentType = "application/pdf" Response.AddHeader("content-length", buffer.Length.ToString()) Response.BinaryWrite(buffer) Response.End() Catch ex As Exception Session("errorMessage") = "FileName = " & strFileName & " -- " & ex.Message Response.Redirect("errorPage.aspx")End Try
Response.End will throw a ThreadAbortException, so I think your Catch block is catching that. Try moving that call outside of the Catch block.
0
jcm4101Author Commented:
Thanks for your response..
I should have mentioned that I had previously tried moving it all outside of the try/catch block with the result that nothing appears to download and nothing opens...
Hmmm... I put your code into a new project, and what I mentioned above was the only issue I encountered. Perhaps more code is necessary.
0
jcm4101Author Commented:
Hi
Once again thanks for your response... I appreciate it..
I think I've worked out the issue....
The gridview is inside an update panel, and there was no full postback happening...
I placed a postback trigger (as opposed to async postback trigger) on the update panel and voila!! Document opened up right away....
Your sanity checking the code helped, so am happy to mark your answer as the solution :-)
Thanks again for helping..
Dave
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.