Not able to read content using OpenXml from Document Created using AltChunk in C#

760 Views Asked by At

I have created a Document using AltChunk, It works well. Also able to see my content properly. But when I tried to read the Document content using openXML. The InnerText is null and when I zip the document the document added using AltChunk are showing over there.

Is there any way to get the content using OpenXML so that I could verify the final document?

1

There are 1 best solutions below

0
On

AltChunk embeds content files into the master file. The master file's document.xml has a simple tag with a relation id pointing out to one of the relations files (document.xml.rels or [Content_Types].xml), which then points to the embedded entry file.

The work of merging the documents is handled by the word processor the first time that a file containing AltChunk markup is opened and re-saved.

If you need to work with the master file after embedding the content files, you have a few options:

  1. Trust AltChunk:

    • The simplest answer is to simply believe that your word processor will render the document with perfect fidelity. Add your content, save the master, move on to the next task.
  2. Ask Word for some help:

    • If you need to work with the master document after embedding content, but still within your program, you can simply start a COM instance of Word and use it to open and resave your master file. Voila, you now have your master file and it's embedded content flattened into a single file. From here, you can resume operations from the OpenXML SDK.
  3. Roll your own:

    • When in doubt, you can always drop into the raw OpenXML markup with the LINQ-toXML. From experience, I can say that this is a great deal more work. Without the OpenXML SDK, you are responsible for managing a complex structure of intertwined XML files.

    • For a recent project, I built a system to read, process, combine, reprocess, and save dozens of .docx files. Working in the raw markup offered us complete control without requiring an installation of Word or additional dependencies. That said, the time required to implement a robust system for merging non-trivial documents should be measured in person-weeks, if not person-months.