IF statement does not work as expected due to quote/speech marks using .NET | QUOTE 34 field

Using aspose word 17.8.
When using mail merge option, if there is a double quote in the content, the output breaks at the point of double quote. We are using IF condition for displaying data.

Find the sample

{ IF { MERGEFIELD sampleData1 } <> “”
“Heading”
}

{ IF { MERGEFIELD sampleData2 } <> “”
“{ MERGEFIELD sampleData2 * MERGEFORMAT }”
}

In this example content in sampleData2 may have data with double quotes, for eg : Hi “All” How are you.

In this case the output will like Hi.

Appreciate all help !

@harikrishnang

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.

Sample.zip (27.0 KB)

Please find the attached.

value for sampleData2 : Hi “All” How are you

@harikrishnang

We have tested the scenario using the latest version of Aspose.Words for .NET 19.5 with following code example and have not found the shared issue. So, please use Aspose.Words for .NET 19.5. We have attached the output document with this post for your kind reference.
output.zip (8.6 KB)

Document doc = new Document(MyDir + "SampleInput.docx");
doc.MailMerge.Execute(new string[] { "sampleData1", "sampleData2" }, new object[] { "Heading1", "Hi \"All\" How are you" });

doc.Save(MyDir + "output.docx");

@tahir.manzoor

In normal cases, its working. But we are using HandleMergeFieldInsertHtml. After that the field value breaks at double quotes. Find the code.

void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
{
if (!_excludedlist.Contains(args.FieldName))
{

            DocumentBuilder builder = new DocumentBuilder(args.Document);
            builder.MoveToMergeField(args.DocumentFieldName);
			args.Document.NodeChangingCallback = new HandleFontNodeChanging(args.Field.Start.Font);
            var fieldvalue = (args.FieldValue != null) ? (string)args.FieldValue : string.Empty;
            byte[] htmlBytes = System.Text.Encoding.UTF8.GetBytes(fieldvalue);             
            MemoryStream htmlStream = new MemoryStream(htmlBytes);                          
            LoadOptions loadOptions = new LoadOptions();
            var baseURI = System.Configuration.ConfigurationManager.AppSettings["InternalWebUrl"];
            loadOptions.BaseUri = baseURI;
            loadOptions.LoadFormat = LoadFormat.Html;
            Document htmldoc = new Document(htmlStream, loadOptions);
            builder.InsertDocument(htmldoc, ImportFormatMode.KeepSourceFormatting);             
            args.Document.NodeChangingCallback = null;                
            args.Text = "";
        }
    }

@harikrishnang

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. We will investigate the issue on our side and provide you more information.

@tahir.manzoor

Please find the attached sample code filesAsposeTroubleshoot.zip (28.8 KB)

@harikrishnang

Please note that Aspose.Words mimics the behavior of MS Word. If you perform the same scenario using the MS Word, you will get the same output. We suggest you please replace the double quote in IF field with { QUOTE 34 } field.

We suggest you please read the following topic.
Word fields - IF statement not working as expected due to quote/speech marks