_XDocumentEventSink2_Event.OnMergeRequest event

Office 2013 and later

Occurs when the merge operation is invoked either from the Microsoft InfoPath user interface or from the command line by using the /aggregate option.

Namespace:  Microsoft.Office.Interop.InfoPath.SemiTrust
Assembly:  Microsoft.Office.Interop.InfoPath.SemiTrust (in Microsoft.Office.Interop.InfoPath.SemiTrust.dll)

event _XDocumentEventSink2_OnMergeRequestEventHandler OnMergeRequest

If the ReturnStatus property of the MergeEventObject object is set to false, InfoPath cancels the merge operation. If an error occurs in the code for the OnMergeRequest event, InfoPath ignores the error and relies on the ReturnStatus property If the ReturnStatus property is not explicitly set, the default value of false is used.

For InfoPath forms stored in a Windows SharePoint Services form library, the OnMergeRequest event also occurs when the MergeDocuments2 method of the OpenXMLDocuments control is executed. For more information on the OpenXMLDocuments control, see the Microsoft SharePoint Products and Technologies 2003 Software Development Kit, which is available on the Microsoft Developer Network (MSDN) web site (http://msdn.microsoft.com/).


There is no user interface (UI) in the InfoPath form design window for creating this event handler. To add this event handler to the project, include the InfoPathEventHandler attribute as it appears in the example.

In the following example, the OnMergeRequest event handler performs a merge operation, and it sets variables to indicate the status of the merge operation:

private bool _merging = false;

public void OnMergeRequest(MergeEvent e)
 // Set global property to indicate that forms are being merged.
 if (e.Index == 0)
  _merging = true;

 e.ReturnStatus = true;
 if ((e.Index + 1) == e.Count)
  _merging = false;
  thisXDocument.UI.Alert("Your request to merge " + e.Count + " files is now complete.");