public static void ExecuteCustomLogicOnEmptyRegions(Document doc, IFieldMergingCallback handler, ArrayList regionsList)
{
// Certain regions can be skipped from applying logic to by not adding the table name inside the CreateEmptyDataSource method.
// Enable this cleanup option so any regions which are not handled by the user's logic are removed automatically.
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions;
// Set the user's handler which is called for each unmerged region.
doc.MailMerge.FieldMergingCallback = handler;
// Execute mail merge using the dummy dataset. The dummy data source contains the table names of
// Each unmerged region in the document (excluding ones that the user may have specified to be skipped). This will allow the handler
// To be called for each field in the unmerged regions.
doc.MailMerge.ExecuteWithRegions(CreateDataSourceFromDocumentRegions(doc, regionsList));
}
// ExEnd:ExecuteCustomLogicOnEmptyRegions