I asked this question and have now got it mostly working.
However I am still getting the titled error and cannot seem to find any reference to anyone that has solved it.
This is driving me insane!
My ASHX C# code looks like this;
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.Buffer = true;
context.Response.Charset = "";
context.Response.AddHeader("Content-Disposition", "inline;filename=file.pdf");
context.Response.ContentType = "application/pdf";
Stream fileStream = publishBookManager.GetFile();
byte[] buffer = new byte[32 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
}
context.Response.BinaryWrite(buffer);
context.Response.Flush();
context.Response.Close();
And my jQuery / javascript looks like;
window.open('/UserControls/download.ashx?format=pdf&bookId=' + bookId, "pdfViewer");
There’s several problems with this code – you write out the content of
bufferwhen you probably meant to write out the contents of your memory stream, which you dispose of without using – but why not just do