We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

mail merge template with XML as datasource


we want to mail merge our existing template with dynamically generated xml file(results of a store procedure is saved as XML) and save the generated document as pdf on a button click event from our vb.net web page. In our template we have a checkbox which will be displayed as checked or unchecked based off  specific field value. Let me know if this is possible using DocIO.


1 Reply

SV Sivasubramani V Syncfusion Team October 2, 2015 11:02 AM UTC

Hi Sarita,

Thank you for interest in syncfusion products.

We cannot use XML data directly as data source, instead we can convert XML data into an equivalent enumerable class objects and then we have performed mail merge operation with respect to the fields available in the template document and convert the resultant document to pdf.

And also we have check the checkbox based on the field value using mailmerge even functionality in Essential DocIO. Kindly use the following code example to achieve the same.

I have attach the template document and xml file in the following link for your testing purpose:

Code example:
'Load the xml file into the data table.

Dim xmlFile As XmlReader

xmlFile = XmlReader.Create("Customer_CheckBox.xml", New XmlReaderSettings())

Dim ds As New DataSet()


'Opens the input template document.

Dim document As New Syncfusion.DocIO.DLS.WordDocument("Template.docx")

' Using Merge events to do conditional formatting during runtime.

AddHandler document.MailMerge.MergeField, AddressOf MergeField_CheckBox

'perform the mail mergefunctionality.


Dim converter As New Syncfusion.DocToPDFConverter.DocToPDFConverter()

'Convert word document into PDF document

Dim pdfDoc As Syncfusion.Pdf.PdfDocument = converter.ConvertToPDF(document)

'Save the file as PDF.



''' Handles the CheckBox event of the MergeField control.

''' </summary>

''' <param name="sender">The source of the event.</param>

''' <param name="args">The <see cref="MergeFieldEventArgs"/> instance containing the event data.</param>

Private Sub MergeField_CheckBox(sender As Object, args As Syncfusion.DocIO.DLS.MergeFieldEventArgs)

'  Check the field is city or not.

    If args.FieldName = "City" Then

         Dim checkBoxVlaue As String = args.FieldValue.ToString()

         ' Checks the field value is Boston or not.

         If checkBoxVlaue = "Boston" Then

             'Enbele the check box is true.

             Dim paragraph As Syncfusion.DocIO.DLS.WParagraph = args.CurrentMergeField.OwnerParagraph

             Dim checkBox As Syncfusion.DocIO.DLS.WCheckBox = GetCheckBox(paragraph)

             If checkBox IsNot Nothing Then

                 checkBox.Checked = True

             End If

         End If

     End If

End Sub

''' <summary>

''' Gets the CheckBox.

''' </summary>

''' <param name="paragraph">The paragraph.</param>

''' <returns></returns>

Private Function GetCheckBox(paragraph As Syncfusion.DocIO.DLS.WParagraph) As WCheckBox

     For i As Integer = 0 To paragraph.ChildEntities.Count - 1

         If TypeOf paragraph.ChildEntities(i) Is WCheckBox Then

             Return TryCast(paragraph.ChildEntities(i), WCheckBox)

         End If


     Return Nothing
End Function

Kindly try this and let us know if this helpful for you?


Live Chat Icon For mobile
Up arrow icon