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

Free Support Forum - aspose.com

Access to Merge Field "switches"/metadata

We have many Word document templates with Merge Fields similar to below. We have a need to “read/access” the “switch”/metadata (in red) that is after the field name but part of the merge field. Using Aspose for Words, how can I do this? I did not see anything on the MailMerge object that would let me do this. The closest thing was a string[] of field names which doesn’t help.

Examples of our merge fields. I’ve also attached an example document

FirstName repeater=1 xPath=Client\ClientContact\FirstName mask= TableName=

HideBegin xPath=Client\ClientLocation\MailAddress2 Compare=’’

MailAddress2 repeater=1 xPath=Client\ClientLocation\MailAddress2 mask= TableName=

Hi there,

Thanks for your inquiry. In your case, I suggest you please use the Field.GetFieldCode method to get text between field start and field separator (or field end if there is no separator). Once you have field codes, you can manipulate it according to your requirement. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "Test1.doc");
foreach (FieldStart fStart in doc.GetChildNodes(NodeType.FieldStart, true))
{
    if (fStart.FieldType == FieldType.FieldMergeField)
    {
        string FieldCode = fStart.GetField().GetFieldCode();
    }
}