We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MailMerge.ExecuteWithRegions doesn't behave in the same way in version and in latest Aspose.Words

Dear Support,

When upgrading my Aspose.Words dll (from to, I realised that the “Aspose.Words.document.MailMerge.ExecuteWithRegions()” method doesn’t behave the same way as before. Could-you please indicate how I could go back to the initial situation with the latest Apsose.Words version?

I attached a sample project showing the problem.



Hi Andy,

Thanks for your inquiry. In your case, I suggest you please pass DataTable or DataSet to MailMerge.ExecuteWithRegions method. Please check the overloaded method of MailMerge.ExecuteWithRegions from here:

Please read following documentation link for your kind reference.

Please check the mail merge with regions code example in Aspose.Words for .NET examples repository at GitHub and let us know if you have any more queries.

Hi Tahir,

I have also tried with the overload “public void ExecuteWithRegions (DataTable dataTable)” and it gives the same result (see the attached code with the 2 aspose dll versions). The merge field is not replaced by an empty value with the latest version and it is with version For my application I would need to keep the behavior of version Do you have any suggestion/solution?



Hi Andy,

for your inquiry. If you want to remove the unused fields, empty
paragraphs, unused regions etc during mail merge process, please use the
MailMerge.CleanupOptions property. Following code snippet shows how to
instruct the mail merge engine to remove any empty paragraphs and unused regions.

|= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs;

doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedRegions;

//doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedFields;

//doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveContainingFields;


doc.Save(MyDir + @"Out.doc");

I suggest you please read following documentation links for your kind reference.

Moreover, you can also delete certain fields from the document by implementing IFieldMergingCallback interface as shown in following code example. Please check the following code example for your kind reference.

Hope this helps you. Please let us know if you have any more queries.

var doc = new Aspose.Words.Document(MyDir + "in.docx");

doc.MailMerge.FieldMergingCallback = new HandleMergeTest31();


doc.Save(MyDir + "Out.docx");

private class HandleMergeTest31 : IFieldMergingCallback


void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)


if (e.TableName == "TableName" && e.DocumentFieldName.Equals("FieldName"))


if (e.FieldValue.ToString().Trim() == "")




void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)


// Do nothing.



Thank you very much!

The option Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedRegions solved my problem.


Hi Andy,

for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.