auto download with page redirection

Discussion in 'ASP .Net' started by Carlo, Dec 14, 2006.

  1. Carlo

    Carlo Guest

    I am trying to seek the following functionality:

    A user clicks on a download buton
    > he is redirected to another page
    > download automatically begins while in page.


    I can automatically download a file, but since in the end i must end the
    response, its either the download or the page display.

    To dowload the file i am using the following code:

    Response.ContentType = "application\\octet-stream";

    string filename = BaseComponents.GetDownloadLink(productRef);

    System.IO.FileStream downloadFile = new System.IO.FileStream(filename,
    System.IO.FileMode.Open);

    Response.AddHeader("Content-Disposition", "attachment; filename=" +
    downloadFile.Name);

    Response.AddHeader("Content-Length", downloadFile.Length.ToString());

    Response.Write(downloadFile.Length + "#");

    downloadFile.Close();

    Response.WriteFile(filename);

    Response.Flush();

    Response.End();
    Carlo, Dec 14, 2006
    #1
    1. Advertising

  2. Carlo

    bruce barker Guest

    you can not send both a file and a redirect. the usual solution to this
    is to have the download load into a new window, then the current page is
    free to redirect whenever it wants. the hickup is that the original page
    can not tell when the download is done. it can poll the server to see if
    the server send is complete, but can not tell if the last block was
    received.

    -- bruce (sqlwork.com)

    Carlo wrote:
    > I am trying to seek the following functionality:
    >
    > A user clicks on a download buton
    >> he is redirected to another page
    >> download automatically begins while in page.

    >
    > I can automatically download a file, but since in the end i must end the
    > response, its either the download or the page display.
    >
    > To dowload the file i am using the following code:
    >
    > Response.ContentType = "application\\octet-stream";
    >
    > string filename = BaseComponents.GetDownloadLink(productRef);
    >
    > System.IO.FileStream downloadFile = new System.IO.FileStream(filename,
    > System.IO.FileMode.Open);
    >
    > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    > downloadFile.Name);
    >
    > Response.AddHeader("Content-Length", downloadFile.Length.ToString());
    >
    > Response.Write(downloadFile.Length + "#");
    >
    > downloadFile.Close();
    >
    > Response.WriteFile(filename);
    >
    > Response.Flush();
    >
    > Response.End();
    >
    >
    >
    bruce barker, Dec 14, 2006
    #2
    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. Prakash

    Auto Download from Web Page

    Prakash, Apr 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    449
    Steve C. Orr [MVP, MCSD]
    Apr 11, 2006
  2. linkswanted
    Replies:
    1
    Views:
    896
  3. Prakash

    Auto Download from Web Page

    Prakash, Apr 10, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    94
    Prakash
    Apr 10, 2006
  4. Thomas Fujita
    Replies:
    1
    Views:
    289
    Kenny
    Oct 22, 2003
  5. James T Kirk
    Replies:
    2
    Views:
    137
    James T Kirk
    Aug 21, 2003
Loading...

Share This Page