Page numbers of TOC are updated incorrectly using C#

Hi Team,

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


Unfortunately, we cannot download the shared document. Could you please ZIP and attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.


Hi Tahir,

Please find the attached zip file.

Uddeshya (53.2 KB)


We have tested the scenario using the latest version of Aspose.Words for .NET 20.3 and have not found the shared issue. So, please use Aspose.Words for .NET 20.3. We have attached the output DOCX with this post for your kind reference. (49.7 KB)


In the attached document you have shared ,i am still able to see the same issue.
I am highlighting the page number mismatch in the document and table of content and attaching the screenshot for your reference:

Uddeshya Pratikpage1.PNG (91.0 KB)
Doc2.PNG (40.7 KB)


Please follow your other thread for further proceedings.