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

# Update Page Numbers for Items Entries in Table of Content TOC Field in Word Documnet C#

@awais.hafeez

Hi Hafeez,

I have tried to update TOC of a document with the code snippet you have posted above

Document doc = new Document("D:\\Temp\\in.docx");

foreach (Field field in doc.Range.Fields)
{
if (field.Type == FieldType.FieldTOC)
{
FieldToc toc = (FieldToc)field;
toc.UpdatePageNumbers();
}
}

doc.Save("D:\\Temp\\18.7.docx");


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.

https://easyupload.io/0w2m5c

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.

Regards,
Uddeshya Pratik

Please find the attached zip file.TOC_ASPOSE_SAMPLE.zip (53.2 KB)

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-20161. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

@awais.hafeez

Did you get a chance to look into the above issue.Please let me know.

Thanks & Regards,
Uddeshya Pratik

Your issue (WORDSNET-20161) is currently ‘pending for analysis’ and is in the queue. We will inform you via this thread as soon as this issue will be resolved. We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-20161) have been fixed in this Aspose.Words for .NET 22.8 update also available on NuGet.