Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.net open pdf in client browser doesn't work...

Posted on 2014-02-05
4
Medium Priority
?
378 Views
Last Modified: 2014-02-05
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

Open in new window


I've tried it in both Chrome (preferred) and IE with the same results...
If I manually paste the file path into chrome the pdf opens without a hitch..

Can anyone shed any light on this please?

Thasnks in advance..

Dave
0
Comment
Question by:jcm4101
[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
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39837891
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
 

Author Comment

by:jcm4101
ID: 39837961
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...

hmmmmmmmm
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1500 total points
ID: 39837965
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.

 Screenshot
0
 

Author Closing Comment

by:jcm4101
ID: 39838004
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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Now-a-days, indirectly, postal services have been replaced by email services. Yes, whenever we hear the word "email" a lot of people only think of gmail. Some people still think that email and gmail are one and the same thing :-). Let's see some …
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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