Free Support Forum -

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

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.MainDocumentType = Settings.MailMergeMainDocumentType.FormLetters
            tmpDocument.MailMergeSettings.DataType = Settings.MailMergeDataType.TextFile
            tmpDocument.MailMergeSettings.DataSource = "Prec_datasource.txt"

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.


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


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