Free Support Forum -

Update fiels don't update the TOC


I have an issue with the method “Aspose.Words.Document.UpdateFields()” which does not update the document TOC.
I did the test with Aspose.Words version 9.7 and the latest version (10.0) and in both cases the TOC is not updated.

I have other Aspose.Words unresolved issues since 4 months which does not allow me to update because those problems are even worse in your latest release (I refer to 24394 (Unresolved); 25171 (Unresolved); 23965 (Unresolved)).
Meaning that ok if you plan to create another ticket in your bug tracker, but what we really need is a workaround to correct the word document so that we can use that aspose feature.
This updatefield method was working fine before we change some styles and layout in the word document.

Please propose a workaround but a programmatic one (not to open the document with Word and save it manually).

I have priority support, and really need quick help.


Hi Dimitri,

Thanks for your request. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

As a temporary workaround, you can use code like the following:


public void Test001()


// Open source document.

Document doc = new Document(@"Test001\U5g_Hypothesis423_1.docx");

// Copy formating from Titre N styles to Heading N styles.

CopyStyleFormating(doc.Styles["Titre 1"], doc.Styles[StyleIdentifier.Heading1]);

CopyStyleFormating(doc.Styles["Titre 2"], doc.Styles[StyleIdentifier.Heading2]);

CopyStyleFormating(doc.Styles["Titre 3"], doc.Styles[StyleIdentifier.Heading3]);

CopyStyleFormating(doc.Styles["Titre 4"], doc.Styles[StyleIdentifier.Heading4]);

CopyStyleFormating(doc.Styles["Titre 5"], doc.Styles[StyleIdentifier.Heading5]);

CopyStyleFormating(doc.Styles["Titre 6"], doc.Styles[StyleIdentifier.Heading6]);

CopyStyleFormating(doc.Styles["Titre 7"], doc.Styles[StyleIdentifier.Heading7]);

CopyStyleFormating(doc.Styles["Titre 8"], doc.Styles[StyleIdentifier.Heading8]);

CopyStyleFormating(doc.Styles["Titre 9"], doc.Styles[StyleIdentifier.Heading9]);

// Change Titre N styles to Heading N styles.

doc.Accept(new HeadingVisitor());

// Update fields.


// Save output.



private static void CopyStyleFormating(Style src, Style dst)


// Copy font formatting.

dst.Font.Name = src.Font.Name;

dst.Font.Size = src.Font.Size;

dst.Font.Bold = src.Font.Bold;

dst.Font.Italic = src.Font.Italic;

dst.Font.Underline = src.Font.Underline;

dst.Font.Color = src.Font.Color;

// ...........

// Copy paragraph formatting.

dst.ParagraphFormat.Alignment = src.ParagraphFormat.Alignment;


private class HeadingVisitor : DocumentVisitor


public override VisitorAction VisitParagraphStart(Paragraph paragraph)


// Reset styles of heading paragraphs.

switch (paragraph.ParagraphFormat.StyleName)


case "Titre 1":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;


case "Titre 2":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;


case "Titre 3":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;


case "Titre 4":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading4;


case "Titre 5":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading5;


case "Titre 6":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading6;


case "Titre 7":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading7;


case "Titre 8":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading8;


case "Titre 9":

paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading9;



return VisitorAction.Continue;



Hope this helps.

Best regards,

Hi, your temporary workaround works. Thank you very much.

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

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