Merge altchunk content into docx source

In short: How to merge altchunks content into source docx files to prevent problems opening docx that has too many altchunks?

Background: I have a docx file with 5000 altchunks that were dynamically inserted when the file was created. Because there are so many altcunks, each with at least 1 page of content, the file will not open in Word - in Word 2010 reports "Word cannot create work file", Word 2007 reports "Too many windows open" and Office interop reports : "The file appears to be damaged."

I believe the source of the problem is that altchunk content is stored in different files in the docx file structure and has to open so many files that exceed some limit. In this case, I would be better off merging the content of the altchunk into the actual docx source. How can i do this?

It's okay if I lose altchunk in the process, or change the definition until the content changes.

Here's an example of how one altchunk is created, given a snippet of HTML htmlText

:

''// add a part to the document for the HTML chunk
Const snippetChunkID As String = "HtmlSnippetChunk"
Dim snippetChunkPart As AlternativeFormatImportPart = currentDocument.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, snippetChunkID)

''// feed HTML into new chunk
Dim stream As New MemoryStream(Encoding.Default.GetBytes("<html><body>" & htmlText & "</body></html>"))
snippetChunkPart.FeedData(stream)
stream.Close()
stream.Dispose()

''// insert chunk after the placeholder element
Dim snippetAltChunk As New AltChunk() With {.Id = snippetChunkID}
placeholderElement.InsertAfter(snippetAltChunk, placeholderElement)

      

+3


source to share





All Articles