Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 29, 2012 08:17 PM by dc2000
Mar 28, 2012 06:42 AM|LINK
Say, if I started file downloading process by outputting headers like so:
Response.ContentType = "application/zip";
Response.AppendHeader("content-disposition", "attachment; filename=\"" + strZipName + "\"");
Response.CacheControl = "Private";
And then later in code I realize that an error ocurred and I need to cancel the download process and instead output the data as HTML (in a normal way). Is there any way to do that?
Mar 29, 2012 07:16 AM|LINK
Once the page has finished processing, the response output is sent to the client. That is the point of no return. Before that point, you can alter the headers that you set by calling the
ClearHeaders method, and the
Clear method if you want to remove any output that might have been buffered.
Mar 29, 2012 07:20 AM|LINK
Thanks. But at what point does the "page finish processing"?
Mar 29, 2012 08:30 AM|LINK
You can do it in a convoluted way.
Mar 29, 2012 01:17 PM|LINK
If you call Response.End or Response.Redirect, the page will terminate processing at that point. Or if you call Response.TransmitFile or Response.BinaryWrite, for example, you cannot then stop the download.
Mar 29, 2012 08:17 PM|LINK
You see, Mike, if I call Response.End() after calling the methods from my first post I get an empty ZIP attachment in a client browser. This obviously will be confusing for a user. What I'm trying to do is to "cancel" the donwload
process and display a web page with an error description instead.