A common trick to accessing the files stored in a DOCX file, is to change the file extension of the DOCX file from DOCX to ZIP.
In preparation for an article that I’ll soon publish about writing the contents of an InfoPath field to a DOCX file, While preparing an article on converting the contents of a Rich Text Box field on an InfoPath form and displaying it in a Word 2007 document, I accidentally came across the following error when I tried to modify a DOCX file outside of the Word 2007 environment and then open it in Word 2007:
The Office Open XML file <filename> cannot be opened because there are problems with the contents.
Details
The file is corrupt and cannot be opened.
While this error can have several causes, it took place when I did the following:
- Change the file extension of the DOCX file from DOCX to ZIP.
- Unzip the ZIP file and store the contents in an unzipped folder.
- Optionally, make modifications to the files in the unzipped folder.
- Use the zip functionality in Windows to zip the unzipped folder back up and create a ZIP file.
- Change the file extension of the ZIP file from ZIP to DOCX.
- Open the DOCX file in Word 2007.
Obviously there is a special way to zip the unzipped folder back up to create a DOCX file, because Word 2007 does not accept just any ZIP format and/or compression. The way around this is to never unzip the ZIP file to a separate folder and then zip the folder back up.
To avoid getting the error above, manually change a DOCX file as follows:
- Change the file extension of the DOCX file from DOCX to ZIP.
- Double-click the ZIP file. A Window containing the folders and files within the ZIP file will open.
- If you need to modify any of the files within the ZIP file, drag that file out of the ZIP file and drop it somewhere on your local PC.
- Change whatever you need to change in the file and save the file.
- Drag the file back to the Window for the ZIP file and drop it in the ZIP file.
- Accept the prompt that asks you whether you want to replace the file.
- Change the file extension of the ZIP file from ZIP to DOCX.
- Open the DOCX file in Word 2007.
