OpenXML converting .docx to .doc

1.8k views Asked by At

I've successfully implemented OpenXML that takes the bookmarks within a document and replaces them. Unfortunately it only works with .docx and from what I understand .doc is not compatible with the OpenXML format.

So, what I'm wondering is if I can take that WordprocessingDocument and convert it to a .doc when users try and download it. Is that possible? If so anyone know how to do that?

2

There are 2 answers

0
Dmitry Pavlov On BEST ANSWER

Converting from DOCX to DOC with Open XML SDK 2.0 is not possible.

10
jn1kk On

Either use a third party library, like Aspose.Words. Or you need to use Microsoft Interop services.

This is sample C# code:

Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDocument = wordApplication.Documents.Open(opath);
wordDocument.SaveAs("BLUH.DOC",  WdSaveFormat.wdFormatDocument);

((Microsoft.Office.Interop.Word._Document)wordDocument).Close(); // cast necessary
((Microsoft.Office.Interop.Word._Application)wordApplication).Quit(); // cast necessary

Take a look at these pages:

FileConverter

SaveFormat

SaveAs