TOC link redirect not working in word

Hello team,

I’ve removed the content control from the Word document, but now my table of contents (TOC) link isn’t working. I’ve added my bookmark inside the content control. How can I resolve this issue? I’ve checked in the backend, and my destination bookmark still exists in the document after removing the content control. How can I resolve this issue?

Snippet :

doc.GetChildNodes(NodeType.StructuredDocumentTag, true).Cast<StructuredDocumentTag>().ToList()
                .ForEach(sdt => sdt.RemoveSelfOnly());

Before Removing Content Control:
TOC1.docx (16.9 KB)

After Removing Content Control:
TOC2.docx (11.0 KB)

@AlpeshChaudhariDev Unfortunately, I cannot reproduce the problem on my side using the latest 24.4 version of Aspose.Words an the following code:

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

doc.GetChildNodes(NodeType.StructuredDocumentTag, true).Cast<StructuredDocumentTag>().ToList()
    .ForEach(sdt => sdt.RemoveSelfOnly());

doc.Save(@"C:\Temp\out.docx");

Here is the produced output: out.docx (11.0 KB)

As I can see you are using a quite old version of Aspose.Words 21.8. Please try using the latest version on your side and let us know if the problem still persists.

1 Like