Table Of Contents - F9?

Hi,

My question is simple, is there a way to insert a TOC and display it in the document without pressing F9 key ?

Thanks,

Q.

Hi
Thanks for your interest in Aspose.Words. Yes of course you can create TOC from scratch using Aspose.Words, please see the following link:
https://reference.aspose.com/words/net/aspose.words/documentbuilder/inserttableofcontents/
Also, if your document already contains TOC field you can call Document.UpdateFields. This will update the TOC field and all other fields in the document. When you call the Document.UpdateFields method, Aspose.Words updates (entirely rebuilds) the TOC field, but does not insert page numbers into the TOC field yet. Aspose.Words calculates correct page numbers and inserts into the TOC when the document layout is built e.g. when you save to PDF or print. So to update page numbers in TOC, you should call Document.UpdatePageLayout or just save document in PDF or XPS.

Document doc = new Document("TestTOC.doc");
doc.UpdateFields();
doc.UpdatePageLayout();
doc.Save("out.doc");

or

Document doc = new Document("TestTOC.doc");
doc.UpdateFields();
doc.SaveToPdf("out.pdf");

Best regards,

Hi,

Thanks for your help !

I have the same kind of problem with page count.
When I add the page number in my document (Exemple: a 5 pages document) my first page has the footer “Page 1 of 1” and the other pages have “Page x of 5”.

Is there a method to update page count ?

Thanks,

Q.

Hi

Thank you for additional information. In this case you can call Document.UpdatePageLayout method. Please see the following link to learn more about update fields:
https://docs.aspose.com/words/net/update-fields/
Bets regards,