1

I have an application that download docx file from a service. The problem is that the service creates the docx with the an old format (I think it used the open xml version 2.0). I don't own the service so I can't change the creation process of the word , but I thought about building a convertor , that will open the downloaded files and recreate them in the newest format using the open xml sdk version 2.5. I was optimistic when I thought this code will work ( A simple open and save) :

WordprocessingDocument  wordprocessingDocument =
                         WordprocessingDocument.Open(filePath, true);
 wordprocessingDocument.MainDocumentPart.Document.Save();

I'm not fimiliar with the open xml sdk , so any help will be appreciated.

madhead
  • 31,729
  • 16
  • 153
  • 201
Tal Humy
  • 1,197
  • 1
  • 18
  • 41
  • What happens when you run this code? – Resource Dec 01 '14 at 09:39
  • Nothing , the format doesn't change – Tal Humy Dec 01 '14 at 13:02
  • What's the particular problem with the document format that you download? OpenXML/Microsoft Office provides pretty good backward compatibility, so usually there should not be issues. If you tell us the exact problems we can possibly provide better help. – Dirk Vollmar Dec 02 '14 at 13:15

1 Answers1

0

You're just opening the doc and saving it with no changes. You need to change the Word version, then save it. This article should provide the info you need: http://blogs.msmvps.com/wordmeister/2013/01/18/openxmlsdk-word-compatibility-mode/

Resource
  • 524
  • 4
  • 16
  • Thank you for your replay but unfortunately it doesn't work. Now I can't event open the document , since some of the characters are not recognized. – Tal Humy Dec 03 '14 at 13:46
  • OK, I hadn't thought of that. Of course, when saved in the new format the contents of the XML are invalid. I think you're better off forgetting about the open XML SDK and using Microsoft.Office.Interop.Word.Application. See the answer here http://stackoverflow.com/questions/607669/how-do-i-convert-word-files-to-pdf-programmatically - you can easily use it as an example to convert to a newer form of Word, rather than to a PDF. – Resource Dec 03 '14 at 14:19