Download links

Discussion in 'ASP .Net' started by Ron, Sep 21, 2004.

  1. Ron

    Ron Guest

    Hi all,

    Probably a simple question... How can I make a link or a button
    download a file instead of just opening it? Thanks.
    Ron, Sep 21, 2004
    #1
    1. Advertising

  2. Ron

    Lucas Tam Guest

    (Ron) wrote in
    news::

    > Probably a simple question... How can I make a link or a button
    > download a file instead of just opening it?


    You need to change the Response.ContentType to an unknown content type.

    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
    Lucas Tam, Sep 21, 2004
    #2
    1. Advertising

  3. Something along these lines should do it:

    Response.ContentType = "application/PDF";
    Response.AppendHeader("content-disposition", "attachment:
    filename=test.pdf");
    Response.WriteFile("c:\test.pdf");

    Here's more info:
    http://msdn.microsoft.com/library/d...fsystemwebhttpresponseclasswritefiletopic.asp
    http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci937876_tax293033,00.html
    http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

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



    "Ron" <> wrote in message
    news:...
    > Hi all,
    >
    > Probably a simple question... How can I make a link or a button
    > download a file instead of just opening it? Thanks.
    Steve C. Orr [MVP, MCSD], Sep 21, 2004
    #3
  4. Ron

    Eric Guest

    Steve C. Orr [MVP, MCSD] wrote:

    > Response.ContentType = "application/PDF";
    > Response.AppendHeader("content-disposition", "attachment:
    > filename=test.pdf");
    > Response.WriteFile("c:\test.pdf");
    >
    > Here's more info:
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref
    > /html/frlrfsystemwebhttpresponseclasswritefiletopic.asp
    > http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci937876_tax293
    > 033,00.html
    > http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp20
    > 0309so_l.asp


    The WriteFile needs a MapPath:

    Response.WriteFile(Server.MapPath(@"c:\test.pdf"));

    Eric
    Eric, Sep 22, 2004
    #4
  5. Ron

    Eric Guest

    Eric wrote:

    > Steve C. Orr [MVP, MCSD] wrote:
    >
    > > Response.ContentType = "application/PDF";
    > > Response.AppendHeader("content-disposition", "attachment:
    > > filename=test.pdf");
    > > Response.WriteFile("c:\test.pdf");
    > >
    > > Here's more info:
    > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpr
    > > ef /html/frlrfsystemwebhttpresponseclasswritefiletopic.asp
    > > http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci937876_tax2
    > > 93 033,00.html
    > > http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp
    > > 20 0309so_l.asp

    >
    > The WriteFile needs a MapPath:
    >
    > Response.WriteFile(Server.MapPath(@"c:\test.pdf"));
    >
    > Eric


    Sorry, I guess it doesn't need MapPath if you specify a full pathname.

    Eric
    Eric, Sep 22, 2004
    #5
    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. Andrew H. Carter
    Replies:
    2
    Views:
    442
    Andrew H. Carter
    Jul 16, 2003
  2. Rob McAninch
    Replies:
    0
    Views:
    375
    Rob McAninch
    Jul 15, 2003
  3. Toby A Inkster
    Replies:
    6
    Views:
    450
    Art Sackett
    Jul 16, 2003
  4. www.westerncartooncards.ca

    Exchange Links < Western Cartoon Cards > Exchange Links

    www.westerncartooncards.ca, Jul 12, 2004, in forum: HTML
    Replies:
    2
    Views:
    1,229
    Toby Inkster
    Jul 12, 2004
  5. Garrett Smith
    Replies:
    14
    Views:
    305
    David Mark
    May 26, 2009
Loading...

Share This Page