DocumentAppendDocument Method (Document, ImportFormatMode)

Appends the specified document to the end of this document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.2
public void AppendDocument(
	Document srcDoc,
	ImportFormatMode importFormatMode


Type: Aspose.WordsDocument
The document to append.
Type: Aspose.WordsImportFormatMode
Specifies how to merge style formatting that clashes.
Shows how to append a document to the end of another document.
// The document that the content will be appended to
Document dstDoc = new Document(MyDir + "Document.docx");

// The document to append
Document srcDoc = new Document(MyDir + "Paragraphs.docx");

// 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(ArtifactsDir + "Document.AppendDocument.docx");
Shows how to use the AppendDocument method to combine all the documents in a folder to the end of a template document.
// Lets start with a simple template and append all the documents in a folder to this document
Document baseDoc = new Document();

// Add some content to the template
DocumentBuilder builder = new DocumentBuilder(baseDoc);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Template Document");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("Some content here");

// Gather the files which will be appended to our template document
// In this case we add the optional parameter to include the search only for files with the ".doc" extension
ArrayList files = new ArrayList(Directory.GetFiles(MyDir, "*.doc")
    .Where(file => file.EndsWith(".doc", StringComparison.CurrentCultureIgnoreCase)).ToArray());
// The list of files may come in any order, let's sort the files by name so the documents are enumerated alphabetically

// Iterate through every file in the directory and append each one to the end of the template document
foreach (string fileName in files)
    // We have some encrypted test documents in our directory, Aspose.Words can open encrypted documents 
    // but only with the correct password. Let's just skip them here for simplicity
    FileFormatInfo info = FileFormatUtil.DetectFileFormat(fileName);
    if (info.IsEncrypted)

    Document subDoc = new Document(fileName);
    baseDoc.AppendDocument(subDoc, ImportFormatMode.UseDestinationStyles);

// Save the combined document to disk
See Also