My problem: When a user clicks an image button on an aspx page the codebehind creates a zip file and then I attempt to stream that zip file to the user.
To stream the file I'm using the following code:
FileInfo toDownload = new FileInfo(fullFileName);
if (toDownload.Exists)
{
Response.Clear();
Response.ContentType = "application/zip";
Response.AppendHeader("Content-Disposition", "attachment;filename=" +
toDownload.Name);
Response.AppendHeader("Content-Length", toDownload.Length.ToString());
Response.TransmitFile(fullFileName);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
When I try to execute this I'm getting the following error on the page:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near 'PK...'.
The PK are the first two characters in a zip file that identify it as a zip file so I know that it's attempting to send the zip file to the browser. However, I get the impression that the browser is trying to interpret and/or render the zip file while I want it to pop-up a download file option.
Ideas?
EDIT: Here's a link to a post from the guy who wrote the above error message.