static void Main(string[] args)
{
string FilePath = @"..\..\..\Sample Files\";
string SrcFileName = FilePath + "Joining Mutiple documents 1.docx";
string DestFileName = FilePath + "Joining Mutiple documents 2.docx";
// The document that the other documents will be appended to.
Document dstDoc = new Document();
// We should call this method to clear this document of any existing content.
dstDoc.RemoveAllChildren();
int recordCount = 1;
for (int i = 1; i <= recordCount; i++)
{
// Open the document to join.
Document srcDoc = new Document(SrcFileName);
// Append the source document at the end of the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
Document doc2 = new Document(DestFileName);
dstDoc.AppendDocument(doc2, ImportFormatMode.UseDestinationStyles);
// If this is the second document or above being appended then unlink all headers footers in this section
// from the headers and footers of the previous section.
if (i > 1)
dstDoc.Sections[i].HeadersFooters.LinkToPrevious(false);
}
dstDoc.Save(DestFileName);
}
}