IF Condition not working properly in Aspose.Words for .Net 19.12

After upgrade Aspose.Words for .Net from 13.5 to 19.12, if condition stops working.
Based on my further research I find out that in 13.5, equal condition in IF was Case Insensitive where as in 19.12 it is Case Sensitive.

We need solution in code so that IF condition works as it was working previously.

If Condition:
If Condition.PNG (3.9 KB)

It will be very helpful if there is any solution or workaround at code level.

@Rakesh2013

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

I have attached here two sample application. Both have sample document.

Sample Application 1 (with Aspose 13.5): Old Aspose 13_5.zip (4.2 MB)

Sample Application 2 (with Aspose 19.12): Latest Aspose 19_12.zip (5.0 MB)

Expectation: Sample Application should (using Latest Aspose 19.12) should work same as Sample Application

Let me know if you need further clarification or information.

@Rakesh2013

You are facing the expected behavior of MS Word. Please note that Aspose.Words mimics the behavior of MS Word. If you perform the same mail merge using MS Word, you will get the same output.

Agree that now Aspose version that we have upgraded mimics the behavior of MS Word. But, we were using 13.5 since long time and now we have upgraded. Thousands of our customers templates are designed that way. Now, we can not change template of each and every customer because Aspose has not maintained backward compatibility.

We are seeing so may problems after upgrading and we just got response from Aspose that it mimics MS Word behavior instead of any real solution.

Before upgrading, I approached this forum earlier to know whether we will get any issues after upgrade. And, I got reply that Aspose is doing thorough testing and there will be no issue. If we would know that we will run into this many issues and we will not get any solution, then we would have not upgraded.

Now, I realized that Aspose is not maintaining any backward compatibility.

@Rakesh2013

Please note that we do not provide support for older released versions of Aspose.Words. Moreover, we do not provide any fixes or patches for old versions of Aspose products either. All fixes and new features are always added into new versions of our products.

We always encourage our customers to use the latest version of Aspose.Words as it contains newly introduced features, enhancements and fixes to the issues that were reported earlier.

The behavior of old version is incorrect and was bug in it. It has been fixed in newer versions of Aspose.Words.

So, is there any way to override evaluation of IF Expression? like any callback function or some other functionality?

@Rakesh2013

You can use properties of FieldIf to modify left and right expression to achieve your requirement. The FieldIf.LeftExpression is used to get or set left part of the comparison expression and ieldIf.RightExpression is used for right part of the comparison expression.

I tried to replace “TRUE” with “True” in IF Condition using LeftExpression property, but I can either replace it with True (without double quote) or \“True\”. Basically, it prints escape characters along with double quotes.
Any solution to print/write string in double quotes?

@Rakesh2013

You can use following code example to get the desired output. The '20.6.Test-Merge.docx" is generated by your code example. We suggest you please use the latest version of Aspose.Words for .NET 20.6.

var doc = new Document(MyDir + "20.6.Test-Merge.docx");
FieldIf field = (FieldIf)doc.Range.Fields[0];
field.LeftExpression = @"TRUE";
field.RightExpression = @"TRUE";

doc.UpdateFields();
doc.Save(MyDir + "20.6.docx");

I already tried this but its not working. It still prints TRUE (without double quote) in document.

I’ve observed that If I use multiple words (ex. “TRUE 1”) in expression, then it print double quotes.

@Rakesh2013

Please make sure that the left and right expression are same e.g. “True” = “True”. If MS Word and Aspose.Words’ results are not same, please share your document and code example here for testing.