Download file and a "dead window"

  • Thread starter Thread starter nino.altran
  • Start date Start date
N

nino.altran

In an aspx page there is the possibility to download a file. I don't
want to give the user a direct link, so I wrote the following code:

.....
try
{
byte[] buff = System.IO.File.ReadAllBytes(path);
int filesize = buff.Length;

Response.ClearHeaders();
Response.AddHeader("Content-type", ContentType);
Response.AddHeader("Content-Disposition", "attachment;
filename=\"" + filename + "\"");
Response.OutputStream.Write(buff, 0, filesize);
Response.OutputStream.Flush();
}
catch
{ .....

I have a problem:
- If I put this code in my page, when the postback is executed the
download starts, but the page "dies" (the postback doesn't render
again my page)
- If I put this code in a new page, loaded in a popup, the download
starts but the popup "dies" (I can't write anything in it and I don't
know how I can close it automatically)

Can someone help me? Thank you in advance!
 
(e-mail address removed) formulated the question :
In an aspx page there is the possibility to download a file. I don't
want to give the user a direct link, so I wrote the following code:

.....
try
{
byte[] buff = System.IO.File.ReadAllBytes(path);
int filesize = buff.Length;

Response.ClearHeaders();
Response.AddHeader("Content-type", ContentType);
Response.AddHeader("Content-Disposition", "attachment;
filename=\"" + filename + "\"");
Response.OutputStream.Write(buff, 0, filesize);
Response.OutputStream.Flush();
}
catch
{ .....

I have a problem:
- If I put this code in my page, when the postback is executed the
download starts, but the page "dies" (the postback doesn't render
again my page)
- If I put this code in a new page, loaded in a popup, the download
starts but the popup "dies" (I can't write anything in it and I don't
know how I can close it automatically)

Can someone help me? Thank you in advance!

You might need a Response.Clear().
I always end these kind of codeblocks with a Response.End() and have no
problem with "dead" pages.

Note: there is also a Response.WriteFile(path) which doesn't need to
buffer the entire file.

Hans Kesting
 
Thank you for your answer, unfortunately my page keeps not working...
but I found a trick to kill the "dead window" with javascript. Thank
you again!
 
Back
Top