TOC is not getting updated when displaying titles from merge field region

Hi Support,

We are using ASPOSE.Word dll.
I’m using mailmerge region and displaying titles as “Header 1” and I wanted it to show up in Table of contents
For some reason titles are not getting displayed in Table of Contents.

Attached is the sample code. Please let me know how I can display titles from mailmerge regions in TOC.

Input and Output files: https://www.screencast.com/t/sXSxvMWOuvD
Update the physical paths in the code accordingly: https://www.screencast.com/t/O7nyvEpl

Here is the sample code:
https://drive.google.com/file/d/1MUGySLMSGkCQkMqMtyv55sYsyMyxGtzY/view?usp=sharing

Tried with v17.12 and v16.70 dll’s but no luck.

Any help is greatly appreciated.
Thanks,
Vijay

@VijaySripada,

You can fix “Table of Contents” field inside output.docx document by using the following code:

Document doc = new Document("D:\\Temp\\output.docx");
doc.UpdateFields();
doc.Save("D:\\Temp\\18.8.docx");

We have updated the TOC field by using MS Word 2016 and the latest version of Aspose.Words for .NET i.e. 18.8 and attach the final output documents here for your reference (see outputs.zip (34.5 KB))

Thanks for the Quick response @awais.hafeez
If I don’t want to upgrade to v 18.8, i should save the out file again so that TOC gets updated.
Correct?

@VijaySripada,

We suggest you please upgrade to the latest version of Aspose.Words i.e. 18.8 and call doc.UpdateFields(); method just before saving to disk. Hope this helps.