Aspose.Words.Examples.CSharp.Programming_Documents.Working_With_Document.InsertDoc.InsertDocumentAtMailMergeHandler.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);

                    // The name of the document to load and insert is stored in the field value.
                    Document subDoc = new Document((string)e.FieldValue);

                    // 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.InsertDocumentAtMailMergeHandler::IFieldMergingCallback ( ImageFieldMergingArgs args ) : void
InsertDoc.InsertDocumentAtMailMergeHandler