Update Table of Contents TOC Field Entries during Converting Word Documents DOC DOCX using C# .NET

When updating from Aspose.Words v19.11.0 to 19.12.0, there is an issue with the table of contents entries when converting to .DOCX.

In v19.11.0, the table of contents has an entry for section 1, as seen in the attached TableOfContents_19-11.docx.

However, when running the same program with v19.12.0, the table of contents says ‘No table of contents entries found.’, as seen in the attached TableOfContents_19-12.docx. Both conversions were run with the same input file, TableOfContents.doc. Also tested with the latest version of Aspose 20.1.0 and the issue persists.

TableOfContents.zip (24.5 KB)

@bmentzer,

Please also share piece of source code that used to generate “TableOfContents_19-11.DOCX” document form “TableOfContents.doc” here for our reference. Thanks for your cooperation.

The following code on our end does not preserve the TOC field when using both the 20.1 and 19.11 versions of Aspose.Words for .NET:

Document doc = new Document("E:\\TableOfContents\\TableOfContents.doc");
doc.Save("E:\\TableOfContents\\20.1.docx");

We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-19797. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

@bmentzer,

During investigating WORDSNET-19797, we have found that the source document is in MHTML format which was created using MS Word and saved with .doc extension. MS Word writes a special “mso-field-code” attribute for TOC code fields that are not yet processed by Aspose.Words.

Can you please explain a bit, how the “TableOfContents_19-11.DOCX” document was generated from the “TableOfContents.doc”. as we suppose it was a binary source .doc file, and not the MHTML saved as “.doc”. Thanks for your cooperation.

We used the following code which worked in 19.11 and not in 20.1:

Document Doc = new Document("E:\\TableOfContents\\TableOfContents.doc");
Builder = new DocumentBuilder(Doc);
foreach (Run n in Doc.FirstSection.GetChildNodes(NodeType.Run, true))
{
	if (n.GetText().Contains("(right click and select 'update field')"))
	{
    	Builder.MoveTo(n);
		string TocType = @"\u";
		Builder.InsertTableOfContents(TocType);
		n.Remove();
    }
}
Doc.UpdateFields();
Doc.Save("E:\\TableOfContents\\TableOfContents_19-11.DOCX");

@bmentzer,

Thanks for the additional information. We have logged these details in our issue tracking system and will keep you posted here on any further updates.