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

前端 未结 7 610
北恋
北恋 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:25

    As variant for .NET Framework 3.5 and lower. This version of framework haven't method CopyTo in class Stream. Therefore, method WriteTo is replaced by next code:

    byte[] arr = documentStream.ToArray();
    fileStream.Write(arr, 0, arr.Length);
    

    Example was found by http://blogs.msdn.com/b/mcsuksoldev/archive/2010/04/09/creating-a-new-microsoft-word-document-from-a-template-using-openxml.aspx

提交回复
热议问题