We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

UpdatePageNumbers updates page numbers incorrectly using C#


Hi Tahir,

I have tried to update TOC of a document with the code snippet mentioned below

Document doc = new Document("D:\\Temp\\in.docx");
foreach (Field field in doc.Range.Fields)
    if (field.Type == FieldType.FieldTOC)
        FieldToc toc = (FieldToc)field;


But in the final generated document still the TOC page numbers not getting updated.
I am attaching the link for the word document for which i have tried this code.


In the document you can see the mismatch of page numbers i.e.:

6.2 Toxicity Management is on page number 28 but in TOC it is showing as page number 27.
Similarly the problem with the following topic numbers and the page references for others.

I have also try to update it with below method:

Document doc = new Document("C:/TOC_Project/Test1.docx");

But still the page number is not getting updated.

Your solution on this will be really helpful for me.

Uddeshya Pratik


We have already answered your query here in this post. Please follow that thread for further proceedings.