Merge docx documents

Is there a way to merge multiple docx documents into one document iwth ASPOSE. I know we have merge but not sure that works.

Hi Jon,

Thanks for your inquiry. You can merge documents by using Document.AppendDocument** Method. Please read following documentation links for your kind reference

Join a Document onto another Document

Please check the following code snippet for your kind reference.

// The document that the content will be appended to.
Document dstDoc = new Document(MyDir + "Document.doc");
// The document to append.
Document srcDoc = new Document(MyDir + "DocumentBuilder.doc");
// Append the source document to the destination document.
// Pass format mode to retain the original formatting of the source document when importing it.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
// Save the document.
dstDoc.Save(MyDir + "Document.AppendDocument Out.doc");

Please let us know if you have any more queries.

*tahir.manzoor:
Hi Jon,

Thanks for your inquiry. You can merge documents by using Document.AppendDocument Method. Please read following documentation links for your kind reference

Join a Document onto another Document
Please check the following code snippet for your kind reference.

// The document that the content will be appended to.
Document dstDoc = new Document(MyDir + "Document.doc");
// The document to append.
Document srcDoc = new Document(MyDir + "DocumentBuilder.doc");
// Append the source document to the destination document.
// Pass format mode to retain the original formatting of the source document when importing it.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
// Save the document.
dstDoc.Save(MyDir + "Document.AppendDocument Out.doc");

Please let us know if you have any more queries.*

This is great Thanks. One thing, it’s merging it at the end of the previous document. Is there a way I can have the second document start on a new page or insert a page break before Appending.
Thanks,
JT

Hi Jon,

Thanks for your inquiry. Yes, you can insert page break before appending document by using DocumentBuilder.InsertBreak method. Please read following documentation links for your kind reference.

https://reference.aspose.com/words/net/aspose.words/breaktype/
https://docs.aspose.com/words/net/document-builder-overview/

DocumentBuilder builder = new DocumentBuilder(dstDoc);
builder.InsertBreak(BreakType.PageBreak);
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

Please let us know if you have any more queries.