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

Free Support Forum - aspose.com

Determine if merge field is within If field

Hi,


I’m trying to figure out the best way to determine if a merge field is located within the TrueText or FalseText of an if statement.

For example, if my template looks like this…

{ IF “A” = “B” “trueText” “{ MERGEFIELD MyMergeField * MERGEFORMAT}” }

how can I be certain that MyMergeField is in one of the result codes as opposed to just sitting on the template outside an if statement?

Hi Gary,


Thanks for your inquiry. You can determine if merge field is in True/False part of IF field by using the following code:

foreach(FieldStart start in doc.GetChildNodes(NodeType.FieldStart, true))

{

if (start.FieldType.Equals(FieldType.FieldIf))

{

FieldIf fieldIf = (FieldIf)start.GetField();

if (fieldIf.FalseText.Contains("MyMergeField"))

{


}

}

}


Hope, this helps.

Best regards,