MailMergeSettings.DataSource not attaching datasource properly Aspose.Words.dll 17.9.0.0

I need to attach a datasource to a Word document. The code completes properly but when I open the saved document using MSWord it says that it cant find the datasource.

The code I am using is;

            Dim tmpDocument As New Aspose.Words.Document("Prec_document.docx")
            tmpDocument.MailMergeSettings.Clear()
            tmpDocument.MailMergeSettings.MainDocumentType = Settings.MailMergeMainDocumentType.FormLetters
            tmpDocument.MailMergeSettings.DataType = Settings.MailMergeDataType.TextFile
            tmpDocument.MailMergeSettings.DataSource = "Prec_datasource.txt"
            tmpDocument.Save("Prec_document.docx")

I attach the document, the datasource and the MSWord error. To reproduce the issue simply run the code above with the attached document and datasource.

Thanks

Datasource not found error.png (17.6 KB)
.Prec_datasource.zip (8.8 KB)

@caseflow4h,

Thanks for your inquiry. Please use the following code example to get the desired output. Hope this helps you.

Dim tmpDocument As Document = New Document((MyDir + "Prec_document.docx"))
Dim dataSource As String = "c:\temp\Prec_datasource.txt"
tmpDocument.MailMergeSettings.Clear
tmpDocument.MailMergeSettings.MainDocumentType = MailMergeMainDocumentType.FormLetters
tmpDocument.MailMergeSettings.DataType = MailMergeDataType.TextFile
tmpDocument.MailMergeSettings.DataSource = dataSource
tmpDocument.MailMergeSettings.Query = String.Format("SELECT * FROM {0}", dataSource)
tmpDocument.Save((MyDir + "out.docx"))

Hi Tahir,

Thanks so much - you are a star!! Now working perfectly