initiating a file download via a Button

Discussion in 'ASP .Net' started by matt@mailinator.com, Nov 22, 2005.

  1. Guest

    hello,

    how does one inititate the dowloading of a file via a button click? for
    example, i have a file sitting on the webserver; when the user clicks
    on a button, i'd like them to see their web browser's "save this file
    to the file system" dialogue and have them download it.

    im not even sure if this would be server-side or client-side. either
    works for me.

    any tips?

    thanks!
    matt
    , Nov 22, 2005
    #1
    1. Advertising

  2. Just redirect the user to that file like you would
    any other url.

    --
    Robbe Morris - 2004/2005 Microsoft MVP C#
    http://www.masterado.net





    <> wrote in message
    news:...
    > hello,
    >
    > how does one inititate the dowloading of a file via a button click? for
    > example, i have a file sitting on the webserver; when the user clicks
    > on a button, i'd like them to see their web browser's "save this file
    > to the file system" dialogue and have them download it.
    >
    > im not even sure if this would be server-side or client-side. either
    > works for me.
    >
    > any tips?
    >
    > thanks!
    > matt
    >
    Robbe Morris [C# MVP], Nov 22, 2005
    #2
    1. Advertising

  3. Guest

    ....that didnt work for me for some reason.

    no sweat tho, i found another way:

    //send file to user
    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AppendHeader("content-disposition", "attachment; filename=" +
    fileName);
    Response.Flush();
    Response.WriteFile(fileAbPath);
    Response.End();

    ....this has an added advantage of allowing me to use a dynamically
    generated filename. cool.


    thanks,
    matt
    , Nov 22, 2005
    #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. Jay
    Replies:
    8
    Views:
    6,559
    livshitz
    Jun 12, 2011
  2. Pavils Jurjans

    ASP page initiating complex code execution

    Pavils Jurjans, Feb 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    364
    Tommy
    Feb 3, 2004
  3. Replies:
    1
    Views:
    349
    souri challa
    Jul 8, 2005
  4. Tim Fooy
    Replies:
    3
    Views:
    1,840
    Tim Fooy
    Aug 13, 2004
  5. Richard L Rosenheim

    Problem displaying page before initiating file download

    Richard L Rosenheim, Jan 30, 2005, in forum: ASP General
    Replies:
    0
    Views:
    123
    Richard L Rosenheim
    Jan 30, 2005
Loading...

Share This Page