0

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?

Mitchell
  • 253
  • 1
  • 5
  • 16

2 Answers2

1

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

Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
0

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

jn1kk
  • 5,012
  • 2
  • 45
  • 72
  • And if I don't have Microsoft Word, Aspose.Words then? – Mitchell May 22 '12 at 13:47
  • AsposeWords costs quite a bit, you might find a cheaper/free third-party library. Just want to reaffirm that you cannot do this with OpenXML SDK. – jn1kk May 22 '12 at 13:48
  • So, caught between a rock and hard place then? – Mitchell May 22 '12 at 13:51
  • More or less. There is always an option to let the user download a free compatibility pack that lets them view docx files on Microsoft Office 2003 platform. – jn1kk May 22 '12 at 13:53
  • Except we're dealing with users that are less than tech savvy. So, we don't want them to call tech support more than they already are. – Mitchell May 22 '12 at 13:55
  • How about letting them downloads PDF's instead? Most users have PDF readers (I think), and there are a lot of libraries (should be quite a few free), that convert docx to pdf. – jn1kk May 22 '12 at 13:57
  • Was actually just suggested to look into that. Have any recommendations? – Mitchell May 22 '12 at 14:13
  • what language you want to use? VB? – jn1kk May 22 '12 at 14:28
  • VB, but never mind. Coworker says that format will not work. So right now I'm just trying to figure out how to save out WordprocessingDocument. Not sure how to do that. – Mitchell May 22 '12 at 14:49
  • You can use JODConverter (a service wrapper for OpenOffice/LibreOffice) to convert from docx to doc – JasonPlutext May 22 '12 at 21:58