I’m trying to import a document and insert it into a specific position using a place holder in a different document.
So my destination is a document like:
{{content}}Where content is where I want to insert the paragraphs from the source document.
First I extract the content of the Source using the code found here:
so I do:
var extractContent = ExtractDocuments.ExtractContent(body.FirstChild, body.LastChild, true);
This leaves me with a list of Paragraphs.
I then traverse to the position:
var documentBuilder = new DocumentBuilder(destinationDoc);
documentBuilder.MoveToMergeField("Content");
and when I run:
foreach (Node node in extractContent)
{
var importedNode = importer.ImportNode(node, true);
documentBuilder.InsertNode(importedNode);
}
I get the error:
‘Cannot insert a node of this type at this location.’
I’ve tried multiple different iterations of this, with the same result. If i append it at the body it works but in the wrong place:
destinationDocument.FirstSection.Body.AppendChild(importedNode); //Works! but wrong place!
Any help would be appreciated.