How to continue bullet numbering on inserted bullet items

  • My ‘main’ document has 5 bullet items, numbered 1 through 5

    • The 4th bullet item has a bookmark.
    • My ‘sub’ document has 2 bullets

    When I insert my ‘sub’ document into the ‘main’ doc (using the InsertDocumentAtNode method listed in Documentation), this is what I end up getting…

    1. main item
    
    1. main item

    2. main item

    3. main item

      1. sub item —
    4. sub item —

    5. main item

    I can fix this in Word, by right clicking on “1. sub item —” and requesting to continue numbering.

    What I would have liked is the numbering to continue without this manual step. Any suggestions?

Thank you,

Raj

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.