Numbered list not resetting when appending more than 2 documents

Hello,

We are trying to Append documents together but after the second document, the numbered lists do not reset. Not sure if we are doing something wrong that it doesn’t reset after page 2. Below is the code we are using and will attach the documents as well. We are using Aspose.Words v16.11.0.0.

Thanks for your help.

Expected numbered lists in Output.doc are:
Page 1: 1. 2. 3. 4.
Page 2: 1. 2.
Page 3: 1. 2.

Actual numbered lists:
Page 1: 1. 2. 3. 4.
Page 2: 1. 2.
Page 3: 3. 4.

Here’s the code we are using:

ArrayList lst = new ArrayList();
lst.Add(@"C:\Temp\1.doc");
lst.Add(@"C:\Temp\2.doc");
lst.Add(@"C:\Temp\3.doc");

Append(lst, @"C:\Temp\OutputTest.doc");
public void Append(ArrayList sourceDocs, String destinationFullPath, bool concatenate = false)
{
    // Initialize document 
    Document destDoc = new Document();
    destDoc.RemoveAllChildren(); // To avoid empty page

    // Append docs
    for (int i = 0; i < sourceDocs.Count; i++)
    {
        // Add new page
        if (i > 0)
            destDoc.LastSection.PageSetup.SectionStart = (concatenate ? SectionStart.Continuous : SectionStart.NewPage);

        // Load document
        Document tmpDoc = new Document(sourceDocs[i].ToString());

        // Convert docProperty fields to static text
        FieldsHelper.ConvertFieldsToStaticText(tmpDoc, Aspose.Words.Fields.FieldType.FieldDocProperty);

        // Set the appended document to appear on the next page.
        tmpDoc.FirstSection.PageSetup.SectionStart = (concatenate ? SectionStart.Continuous : SectionStart.NewPage);
        tmpDoc.LastSection.PageSetup.SectionStart = (concatenate ? SectionStart.Continuous : SectionStart.NewPage);

        // Restart the page numbering for the document to be appended.
        tmpDoc.FirstSection.PageSetup.RestartPageNumbering = true;
        if (destDoc.LastSection != null)
            destDoc.LastSection.PageSetup.RestartPageNumbering = true;

        // Don’t link to previous header/footer
        tmpDoc.LastSection.HeadersFooters.LinkToPrevious(false);

        // Keep track of the lists that are created.
        Hashtable newLists = new Hashtable();

        // Iterate through all paragraphs in the document.
        foreach (Paragraph para in tmpDoc.GetChildNodes(NodeType.Paragraph, true))
        {
            if (para.IsListItem)
            {
                int listId = para.ListFormat.List.ListId;

                // Check if the destination document contains a list with this ID already. If it does then this may
                // cause the two lists to run together. Create a copy of the list in the source document instead.
                if (destDoc.Lists.GetListByListId(listId) != null)
                {
                    List currentList;
                    // A newly copied list already exists for this ID, retrieve the stored list and use it on 
                    // the current paragraph.
                    if (newLists.Contains(listId))
                    {
                        currentList = (List)newLists[listId];
                    }
                    else
                    {
                        // Add a copy of this list to the document and store it for later reference.
                        currentList = tmpDoc.Lists.AddCopy(para.ListFormat.List);
                        newLists.Add(listId, currentList);
                    }

                    // Set the list of this paragraph to the copied list.
                    para.ListFormat.List = currentList;
                }
            }
        }

        // Append
        destDoc.AppendDocument(tmpDoc, ImportFormatMode.KeepSourceFormatting);
    }

    // Save document
    destDoc.Save(destinationFullPath, Aspose.Words.SaveFormat.Doc);
}

Hi Warren,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14563. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Thank you for the update Tahir.

I noticed that Aspose.Wrods for .NET 17.1.0 was released but still don’t see the fix WORDSNET-14563 included. When can we expect this to be available?

Thanks

Hi Warren,

Thanks for your inquiry. We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. Our developers work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is under analysis phase. Once our product team completes the analysis of your issue, we will then be able to provide you an estimate.

Thanks for your patience and understanding.

Thanks for the update Tahir

Tahir,

Aspose.Words for .Net is already on the 3rd release in 2017 and still nothing in regards to WORDSNET-14563. Appears this just keeps sliding past releases/iterations. At this point it just keeps affecting my clients and will have to find another component solution as there’s no resolution in sight. Would understand if we weren’t a paying customer but for the amount of money we pay in license fees each year can’t believe there’s just zero commitment/solution to get a bug fixed within a period of time.

Hi Warren,

Thanks for your inquiry. We have asked for the update from our product team. As soon as any information is shared by them, we will be more than happy to share that with you.

We apologize for your inconvenience.

@MDnetwork,

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we are closing this issue (WORDSNET-14563) as ‘Not a Bug’.

When list copy is added into the source document it does not guarantee that there is no such list in destination document again. To restart list for each inserted document you should add a copy exclusively into the destination document. Please use following code to get the desired output.

public static void Append_modified(ArrayList sourceDocs, String destinationFullPath, bool concatenate = false)
{
    // Initialize document 
    Document destDoc = new Document();
    destDoc.RemoveAllChildren(); // To avoid empty page

    // Array of used in DESTINATION document ListIds.
    ArrayList usedListIds = new ArrayList();

    // Append docs
    for (int i = 0; i < sourceDocs.Count; i++)
    {
        // Load document
        Document tmpDoc = new Document(sourceDocs[i].ToString());

        destDoc.AppendDocument(tmpDoc, ImportFormatMode.KeepSourceFormatting);

        // Keep track of the lists that are created.
        Hashtable newLists = new Hashtable();
        // Collect all used ListIds in current importing document.
        ArrayList curDocUsedListIds = new ArrayList();
        // Iterate through all the inserted sections to check and correct lists if needed.
        Section curSection = destDoc.LastSection;
        for (int j = 0; j < tmpDoc.Sections.Count; j++)
        {
            foreach (Paragraph para in curSection.GetChildNodes(NodeType.Paragraph, true))
            {
                if (para.IsListItem)
                {
                    int listId = para.ListFormat.List.ListId;

                    // Check if the destination document contains a list with this ID already. If it does then this may
                    // cause the two lists to run together. Create a copy of the list in the DESTINATION document instead.
                    if (usedListIds.Contains(listId))
                    {
                        List currentList;
                        // A newly copied list already exists for this ID, retrieve the stored list and use it on 
                        // the current paragraph.
                        if (newLists.Contains(listId))
                        {
                            currentList = (List)newLists[listId];
                        }
                        else
                        {
                            // Add a copy of this list to the document and store it for later reference.
                            currentList = destDoc.Lists.AddCopy(para.ListFormat.List);
                            newLists.Add(listId, currentList);

                            if (!curDocUsedListIds.Contains(currentList.ListId))
                                curDocUsedListIds.Add(currentList.ListId);
                        }

                        // Set the list of this paragraph to the copied list.
                        para.ListFormat.List = currentList;
                    }
                    else
                    {
                        if (!curDocUsedListIds.Contains(listId))
                            curDocUsedListIds.Add(listId);
                    }
                }
            }

            curSection = (Section)curSection.PreviousSibling;
        }

        usedListIds.AddRange(curDocUsedListIds);
    }

    // Save document
    destDoc.Save(destinationFullPath, Aspose.Words.SaveFormat.Doc);
}

Best Regards,
Tahir Manzoor