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

Free Support Forum - aspose.com

Merge Fields outside a region and inside a region

Is there a method to find the merge fields only inside a region or only outside a region? MailMerge.GetFieldNames() will give me all merge fields in the document.

Thanks a lot.

Yes, you can seach for mergefields in any composite node of the document:

NodeCollection nodes = someCompositeNode.GetChildNodes(NodeType.FieldStart, true);

foreach(FieldStart fs in nodes) {

if(fs.FieldType==FieldType.FieldMergeField) {




word4net wanted to get a list of mail merge field names inside a particular mail merge region. A region in the document is not a node (it is a part of the document that consists of many nodes usually), a region is marked itself by two merge fields TableStart:MyTable and TableEnd:MyTable. At the moment there is no way to retrieve merge field names for a specific region, but I added this as a feature request. Will implement soon.

I decided not to provide a method to get merge field names for a specific region at this stage. This feature will be implemented later, when we review the mail merge engine and add support for new things like nested regions.

In the meantime you should be able to achieve what you want with a little extra code:

1. Get all merge field names from the document using MailMerge.GetFieldNames.

2. Loop through the fields. If you encounter a field name "TableStart:MyTable", it means beginning of the region.

3. Keep going through the loop collecting the field names. These field names belong to the region.

4. When you encounter a field name "TableEnd:MyTable", stop collecting field names and terminate the loop.

The issues you have found earlier (filed as 39) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.