Google Chrome - Issues with download dialogs using BinaryWrite
- by Mila
Hello,
I have an empty ASP .NET page with the code behind to support downloading of PDF files. The page is called from a link-like web control that has NavigateUrl set to this page. In short, I am using the following for streaming:
Response.Buffer = false;
Response.ClearHeaders();
Response.ContentType = "application/x-pdf";
Response.AddHeader("Content-Disposition","attachment; filename="MyPDFFile.pdf");
byte[] binary = (dataReaderRemote[DataPDFFieldName]) as byte[]; //dataReaderRemote[DataPDFFieldName] has previously retrieved data
if (binary != null)
{
MemoryStream memoryStream = new MemoryStream(binary);
int sizeToWrite = CHUNKSIZE; //CHUNKSIZE=1024
for (int i = 0; i < binary.GetUpperBound(0) - 1; i = i + CHUNKSIZE)
{
if (!Response.IsClientConnected) return;
if (i + CHUNKSIZE >= binary.Length)
sizeToWrite = binary.Length - i;
byte[] chunk = new byte[sizeToWrite];
memoryStream.Read(chunk, 0, sizeToWrite);
Response.BinaryWrite(chunk);
Response.Flush();
}
}
Response.Close();
IE as well as Firefox bring the download prompt window asking you whether you wish to open or save the file, while the user remains on the same page containing the link. However, Google Chrome opens a new blank tab and downloads the file automatically. Is there any way to prevent Chrome from opening the extra blank and therefore useless tab?
I am using the Google Chrome version 5.0.375.55 (Official Build 47796) on Windows XP.
Thanks in advance!
Mila