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.
Unfortunately, activation email could not send to your email. Please try again.

mail merge template with XML as datasource

Thread ID:

Created:

Updated:

Platform:

Replies:

120667 Oct 1,2015 10:14 AM Oct 2,2015 07:02 AM ASP.NET Web Forms 1
loading
Tags: DocIO
Sarita Gogula
Asked On October 1, 2015 10:14 AM

Hi,

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.

Thanks,
Sarita

Sivasubramani V [Syncfusion]
Replied On October 2, 2015 07:02 AM

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:
http://www.syncfusion.com/downloads/support/forum/120667/ze/Template-1031257524


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()

ds.ReadXml(xmlFile)


'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.

document.MailMerge.Execute(ds.Tables(0))


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.

pdfDoc.Save("DocToPDF")


 <summary>

''' 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

     Next

     Return Nothing
End Function

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

Regards,
Sivasubramani.V





CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;