0

Using a memory stream & the correct MIME type with Response.ContentType. Special characters are displayed instead of prompting to open a Word document. I'm using:

            using (MemoryStream ms = new MemoryStream())
        {
            doc.SaveAs(ms);

            Response.Clear();
            Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
            Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            ms.WriteTo(Response.OutputStream);
            Response.End();
        }

Here's an example of the output I get now rather than a prompt to open a Word document:

enter image description here

Mike
  • 141
  • 10
  • See [What is a correct mime type for docx, pptx etc?](https://stackoverflow.com/questions/4212861). DocX the library doesn't dictate what the correct MIME type is. – mason Nov 20 '17 at 20:48
  • Yes, I have the correct one referenced in Response.ContentType – Mike Nov 20 '17 at 20:49
  • Update - it only works as expected in IE if I change the emulation "document mode" to 8. Any ideas, this is driving me crazy! – Mike Dec 03 '17 at 19:31

1 Answers1

0

Turns out it was not a MIME or Response.ContentType issue at all. Being an MVC application, I was attempting to open the FileResult in a modal. Copy/Paste fail, as other buttons worked this way to display content. Not a Word document!

Mike
  • 141
  • 10