Closing the browser window after a File Download

G

Guest

I'm trying to download a file that is created on the fly from a string, and am using the following code in a new page

_PrintJobData = // a string returned from a metho
_FileName = "PrintJobs_" + System.DateTime.Now.ToString() + ".txt"

Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; filename=" + _FileName)
Response.Flush()
Response.Write(_PrintJobData)
Response.End()

I know that this is a bit of an old chestnut, but I need to close the browser window after the file download dialog appears, and of couse cannot do something like:

Response.Write("<script language=\"javascript\">window.close()</script>")

because Response.End() has been called. Does anybody know of an alternative way of doing this

Thanks
 
P

Patrice

Hummm... How do you call your download page ? I'm almost sure that I call it
directly and as this is not an HTML content the browser doesn't open a new
browser window but just the download file dialog.

If you are using open or a target to open explicity a new window, just call
try to call it directly instead? The browser should figure out that a new
window is not needed.

Patrice


Martin Lee said:
I'm trying to download a file that is created on the fly from a string,
and am using the following code in a new page:
_PrintJobData = // a string returned from a method
_FileName = "PrintJobs_" + System.DateTime.Now.ToString() + ".txt";

Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + _FileName);
Response.Flush();
Response.Write(_PrintJobData);
Response.End();

I know that this is a bit of an old chestnut, but I need to close the
browser window after the file download dialog appears, and of couse cannot
do something like:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top