programmically open a pdf file in vb.net

  • Thread starter Thread starter Cindy H
  • Start date Start date
C

Cindy H

Hi

I have a webpage with a link to a pdf file on it.
Right now the user has to click on the pdf file link to open and display the
file.
Does anyone know how I can get the web page to just open the pdf file
automatically without using a link and the user having to click on it?

Thanks,
CindyH
 
The usual approach is to stream the PDF as the response from your page
request, as opposed to sending a link for the user to click on - or to
simply do a response.redirect to th PDF URL as your only output to your
initial page request (containing your current clickable link)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306654

There are some gotchas that people sometimes fall foul of, and a solution to
some of them explained here:
http://groups.google.co.uk/group/mi....net+PDF+timney&rnum=7&hl=en#29fdd72345009fff
 
Hey - that works great - thank you!


John Timney (MVP) said:
The usual approach is to stream the PDF as the response from your page
request, as opposed to sending a link for the user to click on - or to
simply do a response.redirect to th PDF URL as your only output to your
initial page request (containing your current clickable link)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306654

There are some gotchas that people sometimes fall foul of, and a solution to
some of them explained here:
http://groups.google.co.uk/group/mi....net+PDF+timney&rnum=7&hl=en#29fdd72345009fff
 
Hi

I used the code below, which works great on local machine, but when I
uploaded it to hosting site and then tried it,
I get a window popping up that ask if I want to download or open the file.
Do you know how to get around this?

Thanks,
CindyH

'Set the appropriate ContentType.

Response.ContentType = "Application/pdf"

'Get the physical path to the file.

Dim FilePath As String = MapPath("Reports\CurrentYear_ShootDates.pdf")

'Write the file directly to the HTTP content output stream.

Try

Response.WriteFile(FilePath)

Catch ex As Exception

Response.Redirect("DownloadPDFReader.aspx")

Response.End()

End Try

Response.End()
 
Back
Top