Download file and a "dead window"

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!
 
H

Hans Kesting

(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
 
N

nino.altran

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!
 

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

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top