Problem in Table of Contents while combining documents

Hi Team,
I need to combine two documents and both is having there table of contents.
I need to combine table of contents of both the documents into single table of contents.
Can you please suggest?

Document dstDoc = new Document("fileName");
// The document to append.
Document srcDoc = new Document(outputFile);
// Make the document appear straight after the destination documents content.

srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
////Append the source document to the desination document.

// Pass format mode to retain the original formatting of the source document when importing it.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

dstDoc.Save(excelpath);

Any help on this?
Thanks,
Shyam

Hi Shyam,
Thanks for your request. Could you please attach your documents here for testing? I will check them and provide you more information.
I suppose, you need just remove TOC from the second document and update TOC in the final document after concatenation.
Best regards,

Thanks for your quick response.
You understood right.
You can take any document which have table of content and break that file into two separate file.
And then try to combine both and final document should contain one TOC with all bookmarks details.
Thanks,
Shyam

Hello
Thanks for your request. Have you tried using the way suggested by Alexey in the previous post?
I just checked and it works as expected.
Best regards,

Which post you are talking about?

“I suppose, you need just remove TOC from the second document and update TOC in the final document after concatenation.”

Yes, you are right.
Can you please give me some c# code snippet for doing this?

Hello
Thanks for your request. First of all you should find and remove TOC from the second document. In this case you should use DocumentVisitor:
https://reference.aspose.com/words/net/aspose.words/documentvisitor/
Then you should concatenate your documents as described here:
https://reference.aspose.com/words/net/aspose.words/document/appenddocument/
And then you should just call UpdateFields method.
Best regards,

Hi Andrey,
I was going through the class DocumentVisitor
I do not find any method (to override) VisitTableOf Content.
Which Visisxxx should I use to skip table of content in merging two word document.
Thanks in advance,
Regards
Nakul

Hello
Thanks for your request. Field in MS Word consists of FieldStart, FieldSeparator (not a mandatory part), FieldEnd nodes and Run nodes, which represent field code and field value (displayed text). So in MS Word document field looks like the following:
[FieldStart]here is field code[FieldSeparator]here is field value[FieldEnd]
So in case of using Document visitor you should use VisitFieldStart, VisitFieldSeparator, VisitFieldEnd.
You can also open your document using DocumentExplorer (Aspose.Words demo application) to investigate your document’s structure. DocumentExplorer is included to Aspose.Words installation package. You can find it here:
C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer
Please let me know in case of any issues, I will be glad to help you.
Best regards,

Thanks Andrey,

It is working now… after including VisitFieldStart,VisitFieldSeparator & VisitFieldEnd in Visitor Class.

Regards,
Nakul

Hi Nakul,
It is perfect that you managed to achieve what you need. Please let us know if you need more assistance. We are always glad to help you.
Best regards,

Both The links in this reply are now broken.

Hi,

Thanks for reporting this problem to us. Here are the active links to those pages:

https://reference.aspose.com/words/net/aspose.words/documentvisitor/
https://docs.aspose.com/words/net/insert-and-append-documents/

Please let me know if I can be of any further assistance.

Best regards,