I'm having problems with the TOC in documents created using Aspose.Words that contain a combination of Reporting Services reports (exported to Word format), other stand alone Word documents, and text headings. After calling the UpdateFields() method and saving the resulting document, the TOC contains incorrect page numbers e.g. content on page 10 is shown to be on page 11, etc. Strangely, ctrl+clicking links in the TOC takes me to the correct page. Updating the field in Word (either using the 'Update page numbers only' or the 'Update entire table' options) corrects the numbers however, as you can imagine, this isn't a workable solution.
To insert TOC I'm using the following code:
docBuilder.InsertTableOfContents("\\o \"1-6\" \\h \\z \\u");
To append document contents I do the following:
foreach (Section section in docToBeAdded.Sections)
To add headings:
docBuilder.CurrentParagraph.ParagraphFormat.StyleName = "Heading 1";
docBuilder.WriteLn("Some heading text");
Finally, to update the TOC:
I am desperate for some assistance with this as I'm running out of ideas for a fix.