Free Support Forum -

MailMerge.GetFieldNames() in fields


My code relies on the ability to resolve what mergefields exists on a form. If I create a field like this:

{ IF "{ MERGEFIELD field1 }" = "" "{ MERGEFIELD field2 }" "{ MERGEFIELD
field3 }" }

And then perform this code on it:

string [] mergeFields = doc.MailMerge.GetFieldNames();

Will the string array contain the mergefields?

Logically it should as it is mergefields on the template. But I haven't been able to make it work. These mergefields do not appear anywhere else on the template, only in the IF field.




Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words for .NET 10.5.0. You can download this version from here:

Please see the attached document.

It seems the IF field inside your document does not contain any MergFields just a simple text. To insert one field into another field you should press Ctrl-F9.

Best regards,