ASP.NET: Modify and download docx file

0

I have a docx file which I would like to modify according to web user input. So, after the user submits the form on the web page, I need to modify the original docx file, and then download it to the user.

I try to store the original file as a resource file in my project, but I can't open it programatically. That's what I tried in the post controller:

using Microsoft.Office.Interop.Word;
...
Application app = new Application();
Document document = app.Documents.Open(Properties.Resources.___, ReadOnly: false);

But I received a System.Runtime.InteropServices.COMException (0x80020005 (DISP_E_TYPEMISMATCH))

I also don't know how to download the modified file. In a simple console application document.SaveAs2(newPath); worked, but it doesn't seem to work for downloading.

(I'm not even sure that this whole way could work. If I can't use Microsoft.Office.Interop.Word this way, please let me know.)

c#
asp.net
docx
word-interop
asked on Stack Overflow Sep 11, 2020 by szkup

1 Answer

1

If you want to manipulate docx files it's best to use the OpenXML API rather than the InterOP. See https://docs.microsoft.com/en-us/office/open-xml/open-xml-sdk?redirectedfrom=MSDN

answered on Stack Overflow Sep 12, 2020 by Salik Rafiq

User contributions licensed under CC BY-SA 3.0