7

I'm generating a MS Word document with OpenXml package in C#. Many times I've seen this erorr message:

The file .docx can not be opened because there are problems with the contents

This error message is pretty useless: all it says the problem is in footer. Most of the times it says the error is on line 1, char 1.

I usually find the problem, but it takes too much time by going back and forth.

Are there any tools/techniques that can help with debugging such errors? Show a better error, like you are trying to add a Text outwith of a Run, or something like that?

trailmax
  • 34,305
  • 22
  • 140
  • 234

1 Answers1

8

After poking a bit more online, I found tools that eased the pain. Even made a blog post about it: http://tech.trailmax.info/2014/04/validating-of-openxml-generated-documents-or-the-file-cannot-be-opened-because-there-are-problems-with-contents/

The basics are here:

  1. There is OpenXmlValidator class. Use it like this: http://msdn.microsoft.com/en-us/library/office/bb497334%28v=office.15%29.aspx
  2. There is Open Xml Package Explorer for VSCode - use it for manual tweaking of your stuff and slightly better error messages.

If you know other(better) ways, please let me know!

trailmax
  • 34,305
  • 22
  • 140
  • 234
  • 1
    Running into the same problem, but I'm generating them with php and don't have windows environment, so this doesn't really solve my problem, but your blog post is the first useful bit of information I could find after a long google search and being fed up with painful comparing of my document.xml with the recovered one from Word and figuring out what it doesn't like about it. Thank you! – Matej Svajger Dec 05 '14 at 08:48
  • You are welcome. I also was surprised with the lack of info about this stuff. – trailmax Dec 05 '14 at 10:23
  • the validator save my life ! – Moshe L Jun 06 '19 at 16:30
  • might want to update link for Open XML Package explorer to https://marketplace.visualstudio.com/items?itemName=sergey-tihon.openxml-explorer – lemonskunnk Jan 11 '22 at 20:29
  • @lemonskunnk awesme, thanks! – trailmax Jan 12 '22 at 16:57