Free Support Forum - aspose.com

Mail Merge GetFieldNames

In my template I have a mergeField that has brackets in it’s name ( eg. fieldname() ) … In the template it shows up correctly, but when it is returned from GetFieldNames() the brackets have been stripped… why is this?

Thanks

You probably have () only in the field value, not in the field name. This happens when you edit the text enclosed in << >>.

Turn on display of field codes in Word for all fields and check field names then. What you see in “normal” mode between << and >> symbols is not a field name and editing does not change the actual field name. You can see it if you right click on a field and select Update.

Once you get the field name right, GetFieldNames will return it with () or any other characters except colon and apostrophe as they have special meanings.

I added the mergefield the usual way (insert->field->mergeField)… GetFieldNames doesn’t return the brackets…

Can you email the document to word@aspose.com for a check. I have a test here that shows it works okay.

It definetely works for me. Please check you use the latest version of Aspose.Word as field name parsing has been updated in the last few weeks.

[Test]
public void TestMergeFieldNameWithBrackets()
{
Document doc = TestUtil.OpenSaveOpen(@“X:\Aspose\Aspose.Word\Aspose.Word.Test\Testing\Erin\TemplateWithBrackets.doc”);
string[] fieldNames = doc.MailMerge.GetFieldNames();
Assertion.AssertEquals(“testing()”, fieldNames[0]);
}