Table of Contents questions - problem w/updating

I am working with Aspose.Words for .NET 9.7 (we have a license, but I’m using the eval copy locally), and am trying to do an update to the TOC that the main document has.

The main document is TestTemplate.docx
The plugin(inserted multiple times, in order to “change” the page numbers) is TestPlugin.doc

The plugin is inserted using the standard InsertDocument examples in the Aspose documentation.

The resulting document is TestRepagination.doc

(all of these files should be attached)

Now, after performing the code entered below, the result document does show the proper page numbers, but the problem appears to be the headings for the TOC. Namely, the fields appear to pick up some of the formatting of the headings of the H1, etc after the call to UpdateFields.

So my questions are:

a) Am I doing something incorrectly in my code so that the TOC isn’t updating right?
b) If the code is correct, is there a switch missing in the TOC or some issue with the source document causing the problem?
c) If this is expected behavior, how can I “reapply” the TOC style accordingly?

Aspose.Words.Document doc = new Aspose.Words.Document("C:\\Projects\\TestTemplate.docx");
Aspose.Words.Document pluginDoc = new Document("C:\\Projects\\TestPlugin.doc");

doc.Range.Replace(new Regex("\\[TEST_PLUGIN\\]"), new DocReplaceHandler(pluginDoc), false);

Session["CURRENT_DOC"] = doc;

doc.UpdateFields();
doc.UpdatePageLayout();
doc.Save("C:\\Projects\\TestRepagination.doc", SaveFormat.Doc);

Thanks,
Warren

Thank you for your inquiry
We managed to reproduce your problem. I have registered an appropriate request in our defects database. Once the problem is solved, we will notify you immediately.
As a workaround you can try this code:

Aspose.Words.Document doc = new Aspose.Words.Document("E:\\TestTemplate.docx");
Aspose.Words.Document pluginDoc = new Document("E:\\TestPlugin.doc");
doc.Range.Replace(new Regex("\\[TEST_PLUGIN\\]"), new DocReplaceHandler(pluginDoc), false);
ResetRestoreHeadingFormating(doc, false);
doc.UpdateFields();
ResetRestoreHeadingFormating(doc, true);
doc.Save("E:\\out.doc");
private void ResetRestoreHeadingFormating(Document doc, bool restore)
{
    // Get collection of paragraphs.
    NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
    foreach(Paragraph paragraph in paragraphs)
    {
        // If paragraph is heading we shouwl reset or restore formating.
        StyleIdentifier identifier = paragraph.ParagraphFormat.StyleIdentifier;
        if (identifier == StyleIdentifier.Heading1 ||
            identifier == StyleIdentifier.Heading2 ||
            identifier == StyleIdentifier.Heading3)
        {
            Color textColor = restore ? doc.Styles[identifier].Font.Color : Color.Empty;
            // Set color of runs within a heading paragraph.
            foreach(Run run in paragraph.Runs)
            {
                run.Font.ClearFormatting();
                run.Font.Color = textColor;
            }
        }
    }
}

Thanks for the response. I will try this code and see what results.

Warren

The issues you have found earlier (filed as 25674) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.