G
Gibby
A few weeks back, a message was posted regarding how to force a file
download to a client. The code for this technique is shown at the end
of this message.
A question I have about this technique is how to gracefully get back
to one's web app after doing the file download? Does one just do the
transfer by opening the download page in a separate browser window and
leave the "empty" browser for the user to close or is there a more
elegant way to handle this?
TIA,
Paul
======================================================
private void Page_Load(object sender, System.EventArgs e)
{
string path = Server.MapPath(Request.ApplicationPath +
"/test.acp");
System.IO.FileInfo file = new System.IO.FileInfo(path);
// clear the current output content from the buffer
Response.Clear();
// add the header that specifies the default filename for the
// Download/SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename="
+
file.Name);
// add the header that specifies the file size, so that the
browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());
// specify that the response is a stream that cannot be read by
the
// client and must be downloaded
Response.ContentType = "application/octet-stream";
// send the file stream to the client
Response.WriteFile(file.FullName);
// stop the execution of this page
Response.End();
}
download to a client. The code for this technique is shown at the end
of this message.
A question I have about this technique is how to gracefully get back
to one's web app after doing the file download? Does one just do the
transfer by opening the download page in a separate browser window and
leave the "empty" browser for the user to close or is there a more
elegant way to handle this?
TIA,
Paul
======================================================
private void Page_Load(object sender, System.EventArgs e)
{
string path = Server.MapPath(Request.ApplicationPath +
"/test.acp");
System.IO.FileInfo file = new System.IO.FileInfo(path);
// clear the current output content from the buffer
Response.Clear();
// add the header that specifies the default filename for the
// Download/SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename="
+
file.Name);
// add the header that specifies the file size, so that the
browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());
// specify that the response is a stream that cannot be read by
the
// client and must be downloaded
Response.ContentType = "application/octet-stream";
// send the file stream to the client
Response.WriteFile(file.FullName);
// stop the execution of this page
Response.End();
}