Hi
Thanks for your request. I modified InserDocument method. Please try using the following code:
private void InsertDocument(Node insertAfterNode, Document srcDoc)
{
// Make sure that the node is either a pargraph or table.
if ((!insertAfterNode.NodeType.Equals(NodeType.Paragraph)) &
(!insertAfterNode.NodeType.Equals(NodeType.Table)))
throw new ArgumentException("The destination node should be either a paragraph or table.");
Document dstDoc = insertAfterNode.Document;
// We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.ParentNode;
// Declare temporary list
List tmpList = null;
if (insertAfterNode.NodeType == NodeType.Paragraph)
{
if (((Paragraph)insertAfterNode).IsListItem)
{
tmpList = ((Paragraph)insertAfterNode).ListFormat.List;
}
}
// Create one more temporary list
// that is needed to detect whether new list is started in the source document
List srcList = null;
// Loop through all sections in the source document.
foreach (Section srcSection in srcDoc.Sections)
{
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach (Node srcNode in srcSection.Body)
{
Paragraph para = srcNode as Paragraph;
// This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = dstDoc.ImportNode(srcNode, true);
// Check, if paragraph is ListItem and numbering should be started at 1
if ((para != null) && para.ParagraphFormat.IsListItem)
{
bool isNewList = false;
if (!para.ListFormat.List.Equals(srcList))
{
if (srcList != null)
isNewList = true;
srcList = para.ListFormat.List;
}
if (tmpList == null || isNewList)
{
tmpList = (newNode as Paragraph).ListFormat.List;
}
// Set list
((Paragraph)newNode).ListFormat.List = tmpList;
}
// Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
Hope this helps.
Best regards.