Results 1 to 6 of 6

Thread: How to open PDF in Reader rather than download file

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2021
    Posts
    13

    How to open PDF in Reader rather than download file

    I've inherited a VB.net application that uses a button click to open PDF files stored on a server. I want the PDF to open in Adobe Reader, but the following code downloads the file instead. How can I open it in Reader?

    Code:
    ...
    
    Response.Buffer = False
    Response.Clear()
    Response.ClearContent()
    Response.ClearHeaders()
    Response.ContentType = "application/pdf"
    Response.AddHeader("Content-disposition", "attachment; filename=" & name)
    Response.TransmitFile("c:\12345.pdf")
    Response.End()
    Last edited by Rhodo; Dec 2nd, 2021 at 02:27 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,503

    Re: How to open PDF in Reader rather than download file

    You could continue with that code, then immediately after that…

    Code:
    Process.Start(“c:/12345.pdf”)

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,579

    Re: How to open PDF in Reader rather than download file

    The op's code is on the server tho... so using Process.Start isn't going to work... They're transmitting a PDF file from the server to the client... and the client is downloading the file rather than opening it in Reader. As far as I know there isn't anything on the server side you can do to change that. It's a client issue.

    I'm truying to remember if a plugin in is needed or not... I work on an app that does PDFs and they just open in the browser, but it's been so long since I set it up, I don't remember exactly how I did it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2021
    Posts
    13

    Re: How to open PDF in Reader rather than download file

    Thanks for your help! I found I can prevent download with the following code change. This opens PDF in same tab of browser. If no convenient way to open in Adobe Reader, is there a way to open in new tab?

    Code:
    Response.AddHeader("Content-disposition", "inline; filename=" & name)

  5. #5
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,958

    Re: How to open PDF in Reader rather than download file


  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2021
    Posts
    13

    Re: How to open PDF in Reader rather than download file

    This method worked. Thanks jdc2000!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width