Streaming In Memory Word Document using OpenXML SDK w/ASP.NET results in “corrupt” document

前端 未结 7 636
北恋
北恋 2021-01-01 15:01

I am unable to stream a word document that I create on the fly down to the browser. I am constantly getting a message from Microsoft Word that the document is corrupt.

7条回答
  •  清酒与你
    2021-01-01 15:39

    To expand on Rodion's answer and match the variables used in the questions this is what worked for me:

    Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    Response.AppendHeader("Content-Disposition", "attachment;filename=HelloWorld.docx");
    mem.Position = 0;
    byte[] arr = mem.ToArray();
    Response.BinaryWrite(arr);
    Response.Flush();
    Response.End();
    

提交回复
热议问题