auto download with page redirection

  • Thread starter Thread starter Carlo
  • Start date Start date
C

Carlo

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();
 
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)
 
Back
Top