I'm using the code below which creates a document and some sample text, except the sample text does not appear when I open the document.
Can anyone help me out here?
Thanks
Can anyone help me out here?
Thanks
protected void cmdGenerate_Click(object sender, EventArgs e) { using (MemoryStream mem = new MemoryStream()) { // Create Document using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true)) { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); new Document(new Body()).Save(mainPart); // Assign a reference to the existing document body. Body body = mainPart.Document.Body; // Add new text. Paragraph para = body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); run.AppendChild(new Text("this is sample text")); mainPart.Document.Save(); // Stream it down to the browser Response.AppendHeader("Content-Disposition", "attachment;filename=" + txtManufacturer.Text + ".docx"); Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; mem.CopyTo(Response.OutputStream); wordDocument.Close(); Response.End(); } } }