Check wether mergefield exists


For a customer of ours we use aspose word for filling mergefields in templatedocuments chosen by the user of the website. Sometimes not all mergefields exist in the template.

Is there a way to check wether a mergefield existst in a Word document using Aspose.Word? If not will this be implemented in future releases?

I now use a try… catch for figuring this out, but this isn’t the best way in my opinion.

Futhermore it would be nice if it is possible to loop through a mergefield collection in a word document. Is there a possibility for this to be implemented?



Thank you for your interest in Aspose products.

First, you can use the MailMerge.GetFieldNamesEx method for this purpose. Second, does a missed mergefield throw an exception while performing mail merge on your template? It should be simply ignored.


Thanks a lot, that’s exactly what I meant!

The exception is thrown when the DocumentBuilder.MoveToMergeField can’t find the mergefield. This is the way I used to do it, but looping through it is far more efficient.


Bas van Beek