0
votes

I created a Word 2013 document and did the following:

  1. Added a Plain Text Content Control to it at design time.
  2. Added a Custom Xml Part at design time.
  3. Did a mapping from one node of Custom Xml Part to the Plain Text Content Control.
  4. The value of node appeared in the Content control.
  5. I saved and closed the document.
  6. Renamed it to .zip and extracted it to a folder.
  7. Edited the file in folder customXml/item1.xml which is my custom xml part and changed the value of node from <Name>John</Name> to <Name>Harry</Name>.
  8. Re archived it as a zip file and renamed it to .docx.
  9. When I opened the document, it was corrupted and Microsoft Word says:-

We're sorry. We can't open XYZ.docx because we found a problem with the contents. Microsoft Office cannot open this file because some parts are missing or invalid.

2
With which program you zipped it? - Sarvesh Mishra
With WinRar, but how does it matter, the ZIP format is same. - teenup
I guess your problem is step 8 - JasonPlutext
I also do this but with Windows provided zipping tool... Right click->Send to->Compressed, and never get complaints. Sometimes the the compression level applied, does matter. - Sarvesh Mishra

2 Answers

0
votes

Reason - You cannot unzip and re-zip your .docx file as you did in Step 8

Guide - Try this. Create a dummy .docx file form word. Extract it and re-zip it and try to open the file. You will get the same error and you will not be able to use it as you expect.

Solution - If you want to edit your .docx file , use Open XML SDK and do it. Here is a link to a good guide - http://msdn.microsoft.com/EN-US/library/office/cc850833(v=office.15).aspx . And also Open XML productivity tool will come in handy - http://dotnet.dzone.com/articles/using-openxml-sdk-productivity

0
votes

I was zipping and unzipping incorrectly. We don't need any Open XML SDK.

What I was doing was: Right click on XYZ.docx.zip and select Extract to XYZ.docx. When it got extracted into the folder XYZ.docx, I edited the contents inside and then zipped the entire folder to XYZ.docx which is wrong.

When I got inside of folder and zipped only the contents to XYZ.docx.zip, it started working.