Aspose.Words.Examples.CSharp.Programming_Documents.Working_With_Document.InsertDoc.InsertDocumentAtMailMergeBlobHandler.IFieldMergingCallback C# (CSharp) Method

IFieldMergingCallback() private method

This handler makes special processing for the "Document_1" field. The field value contains the path to load the document. We load the document and insert it into the current merge field.
private IFieldMergingCallback ( FieldMergingArgs e ) : void
e FieldMergingArgs
return void
            void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
            {
                if (e.DocumentFieldName == "Document_1")
                {
                    // Use document builder to navigate to the merge field with the specified name.
                    DocumentBuilder builder = new DocumentBuilder(e.Document);
                    builder.MoveToMergeField(e.DocumentFieldName);

                    // Load the document from the blob field.
                    MemoryStream stream = new MemoryStream((byte[])e.FieldValue);
                    Document subDoc = new Document(stream);

                    // Insert the document.
                    InsertDocument(builder.CurrentParagraph, subDoc);

                    // The paragraph that contained the merge field might be empty now and you probably want to delete it.
                    if (!builder.CurrentParagraph.HasChildNodes)
                        builder.CurrentParagraph.Remove();

                    // Indicate to the mail merge engine that we have inserted what we wanted.
                    e.Text = null;
                }
            }

Same methods

InsertDoc.InsertDocumentAtMailMergeBlobHandler::IFieldMergingCallback ( ImageFieldMergingArgs args ) : void
InsertDoc.InsertDocumentAtMailMergeBlobHandler