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: 19.9
Syntax
public void AppendDocument(
	Document srcDoc,
	ImportFormatMode importFormatMode
)

Parameters

srcDoc
Type: Aspose.WordsDocument
The document to append.
importFormatMode
Type: Aspose.WordsImportFormatMode
Specifies how to merge style formatting that clashes.
Examples
Shows how to append a document to the end of another document.
[C#]

// 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(ArtifactsDir + "Document.AppendDocument.doc");
Examples
Shows how to use the AppendDocument method to combine all the documents in a folder to the end of a template document.
[C#]

// 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.
files.Sort();

// 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)
        continue;

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

// Save the combined document to disk.
baseDoc.Save(path);
See Also