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

Free Support Forum - aspose.com

IF field LeftExpression, RightExpression, ComparisonOperator return incorrect output using .NET


I noticed issue with mergefield in if statement.
Firstly, finding all fields in document in reverse order, to go to merge field before processing if.
Located 1st mergefield, then I’m creating fieldMergeField with text updated, cause I would like to have additional info there. Later, I’m removing old mergefield and processing through fields further.
I located fieldIf and I would like to get values for LeftExpression, RightExpression, etc, but the values are mixed there.
This issue appears only when the mergefield wasn’t provided in quotation marks in template.
When mergefield is put in quotation marks, the values are returned as expected.
Can you advice?

        var document = new Document($"D:\\\ifWithMergefield.dotx"); //ifWithMergefieldInQuotes 
        var builder = new DocumentBuilder(document);
        foreach (var field in document.Range.Fields.Reverse())
            if (field.Type == FieldType.FieldMergeField)
                var fieldCode = "<Mergefield name=" + "{0}" + " />";
                var mergefield = field as FieldMergeField;
                var name = mergefield.FieldName;
                builder.MoveToField(field, false);
                var stringToInput = string.Format(fieldCode, name);

            if (field.Type == FieldType.FieldIf)
                var fieldIf = field as FieldIf;
                Console.WriteLine("LeftExpression: " + fieldIf.LeftExpression);
                Console.WriteLine("RightExpression: " + fieldIf.RightExpression);
                Console.WriteLine("ComparisonOperator: " + fieldIf.ComparisonOperator);
                Console.WriteLine("TrueText: " + fieldIf.TrueText);
                Console.WriteLine("FalseText: " + fieldIf.FalseText);                   

mergefieldInIf.zip (31.4 KB)


We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-20575 . You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Is there an update on this? WORDSNET-20575 seems to be closed…


It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-20575) as ‘Not a Bug’.

It is expected that the FieldIf 's properties will be a mess because even MS Word evaluates the field to name=client which is certainly not something you expect. Please check the attachment. If Condition.PNG.jpg (13.4 KB)

The quotes should be used to designate the arguments of the field if they have spaces, equality sign etc.