I am using similar code with a few differences:
Response.Clear();
MemoryStream ms = new MemoryStream(pdfByte);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
Response.End();
- Call Reponse.Clear() earlier.
- Use MemoryStream.WriteTo to write to Response.OutputStream.
Edit: sorry, I didn't see that you are using ASP.NET MVC, the above code is in a WebForms aspx page.
For ASP.NET MVC, couldn't you just do
return new FileStreamResult(ms, "application/pdf");
?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…