How to force download?

Discussion in 'ASP .Net' started by Miguel Dias Moura, Apr 19, 2004.

  1. Hello,

    in my web site i display some links to PDF files. This links are loaded from
    a database.
    Anyway, when i click these links the PDF files are open in the visitors
    browser and in Acrobat.

    How can i force the files to be downloaded when the person clicks the link?
    I don't want to use zip files.

    Thank You,
    Miguel
     
    Miguel Dias Moura, Apr 19, 2004
    #1
    1. Advertising

  2. Use Response.Writefile to output the PDF file.
    http://msdn.microsoft.com/library/d...fsystemwebhttpresponseclasswritefiletopic.asp

    Then add a line of code like this:
    Response.AddHeader("Content-Disposition","attachment;filename=myfile.pdf");
    The "attachment" specification requests the browser to download the file
    instead of opening it. But ultimately it is up to the browser and the user
    to decide what they want to do with the file; you don't have 100% control of
    this from the server.

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "Miguel Dias Moura" <> wrote in message
    news:...
    > Hello,
    >
    > in my web site i display some links to PDF files. This links are loaded

    from
    > a database.
    > Anyway, when i click these links the PDF files are open in the visitors
    > browser and in Acrobat.
    >
    > How can i force the files to be downloaded when the person clicks the

    link?
    > I don't want to use zip files.
    >
    > Thank You,
    > Miguel
    >
    >
    >
     
    Steve C. Orr [MVP, MCSD], Apr 19, 2004
    #2
    1. Advertising

  3. Miguel Dias Moura

    Dan Brussee Guest

    The closest Ive come to controlling this behavior is to put the PDF in
    a zip file. A total kludge would be to rename the file with a pdx
    extenstion and prompt the user to rename the file during the save step
    to a pdf extension.


    On Mon, 19 Apr 2004 13:31:10 -0700, "Steve C. Orr [MVP, MCSD]"
    <> wrote:

    >Use Response.Writefile to output the PDF file.
    >http://msdn.microsoft.com/library/d...fsystemwebhttpresponseclasswritefiletopic.asp
    >
    >Then add a line of code like this:
    >Response.AddHeader("Content-Disposition","attachment;filename=myfile.pdf");
    >The "attachment" specification requests the browser to download the file
    >instead of opening it. But ultimately it is up to the browser and the user
    >to decide what they want to do with the file; you don't have 100% control of
    >this from the server.
     
    Dan Brussee, Apr 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PJS

    Force Download - XML problem

    PJS, Jul 18, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    521
  2. Ken Cox [Microsoft MVP]

    Re: Force File Download XML Problem

    Ken Cox [Microsoft MVP], Jul 19, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    711
  3. localhost

    Force Download Not Working

    localhost, Jun 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    366
    Steven Cheng[MSFT]
    Jun 30, 2004
  4. tma

    Force download rather than view

    tma, Aug 7, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    834
    =?Utf-8?B?SmVyZW15IERhdmlz?=
    Aug 8, 2004
  5. tma

    Force download Part 2

    tma, Aug 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    382
    Steve C. Orr [MVP, MCSD]
    Aug 11, 2004
Loading...

Share This Page