I'm just starting to explore OpenXml and I'm trying to create a new simple word document and then download the file
Here's my code
[HttpPost]
public ActionResult WordExport()
{
var stream = new MemoryStream();
WordprocessingDocument doc = WordprocessingDocument.Create(stream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true);
MainDocumentPart mainPart = doc.AddMainDocumentPart();
new Document(new Body()).Save(mainPart);
Body body = mainPart.Document.Body;
body.Append(new Paragraph(
new Run(
new Text("Hello World!"))));
mainPart.Document.Save();
return File(stream, "application/msword", "test.doc");
}
I was expecting that it would contain 'Hello World!' But when I download the file, the file is empty
What am I missing? Tks