When creating a document, use MemoryStream as the backup storage. Then create and close the document as usual and transfer the contents of the memory stream to the client.
using(var stream = new MemoryStream()) { using(var doc = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document, true) { ... } stream.Position = 0; stream.CopyTo(Response.OutputStream); }
Do not just grab MainDocumentPart , because, as the name implies, this is just one part of the document package, not all.
You will also need to set response headers for the type of content and its location.
source share