I created a Word 2013 document and did the following:
- Added a Plain Text Content Control to it at design time.
- Added a Custom Xml Part at design time.
- Did a mapping from one node of Custom Xml Part to the Plain Text Content Control.
- The value of node appeared in the Content control.
- I saved and closed the document.
- Renamed it to .zip and extracted it to a folder.
- 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>. - Re archived it as a zip file and renamed it to .docx.
- 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.
I was zipping and unzipping incorrectly. We don't need any Open XML SDK.What I was doing was: Right click on
XYZ.docx.zipand selectExtract to XYZ.docx. When it got extracted into the folderXYZ.docx, I edited the contents inside and then zipped the entire folder toXYZ.docxwhich is wrong.When I got inside of folder and zipped only the contents to
XYZ.docx.zip, it started working.