Home All Groups Group Topic Archive Search About

programmically open a pdf file in vb.net

Author
2 Jul 2006 4:46 PM
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

Author
2 Jul 2006 9:23 PM
John Timney (MVP)
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/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/6e37cf96f8c9a50e/29fdd72345009fff?lnk=st&q=asp.net+PDF+timney&rnum=7&hl=en#29fdd72345009fff

--
Regards

John Timney (MVP)


Show quoteHide quote
"Cindy H" <nonn***@nowhere.com> wrote in message
news:uwQaccfnGHA.1604@TK2MSFTNGP03.phx.gbl...
> 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
>
>
Author
3 Jul 2006 2:27 PM
Cindy H
Hey - that works great - thank you!


"John Timney (MVP)" <x_j***@timney.eclipse.co.uk> wrote in message
news:SrydneI1iqL8pDXZRVnyvQ@eclipse.net.uk...
> 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/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/6e37cf96f8c9a50e/29fdd72345009fff?lnk=st&q=asp.net+PDF+timney&rnum=7&hl=en#29fdd72345009fff
Show quoteHide quote
>
> --
> Regards
>
> John Timney (MVP)
>
>
> "Cindy H" <nonn***@nowhere.com> wrote in message
> news:uwQaccfnGHA.1604@TK2MSFTNGP03.phx.gbl...
> > 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
> >
> >
>
>
Author
3 Jul 2006 3:37 PM
Cindy H
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()





"John Timney (MVP)" <x_j***@timney.eclipse.co.uk> wrote in message
news:SrydneI1iqL8pDXZRVnyvQ@eclipse.net.uk...
> 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/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/6e37cf96f8c9a50e/29fdd72345009fff?lnk=st&q=asp.net+PDF+timney&rnum=7&hl=en#29fdd72345009fff
Show quoteHide quote
>
> --
> Regards
>
> John Timney (MVP)
>
>
> "Cindy H" <nonn***@nowhere.com> wrote in message
> news:uwQaccfnGHA.1604@TK2MSFTNGP03.phx.gbl...
> > 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
> >
> >
>
>