I am doing a mailmerge with Aspose.Words, but when I open the output file with MS Word, I get some messages/errors:
"The file cannot be opened because there are problems with the contents. Details: The file is corrupt and cannot be opened."
I click "OK", then:
"We found unreadable content in the "file name". Do you want to recover the contents of this document?"...
I clicked "Yes", and the document opens.
Can something be done so I don't the error messages?
This is the code I am using (see last 3 lines of code):
Dim values() As Object = Nothing
Dim columnNames() As String
Dim dbConn As SqlConnection = Context.Session("DBConnection")
Dim cmd_proc As New SqlCommand("SELECT data.* FROM dbo.fn_WordMerge(1) AS data", dbConn)
cmd_proc.CommandType = Data.CommandType.Text
Dim dr As SqlDataReader = cmd_proc.ExecuteReader(Data.CommandBehavior.SingleRow)
Dim Flds As New List(Of String)
For I As Integer = 0 To dr.FieldCount - 1
Flds.Add(dr.GetName(I))
Next
columnNames = Flds.ToArray()
Dim RetValues As New ArrayList()
If dr.Read() Then
ReDim values(dr.FieldCount - 1)
dr.GetValues(values)
End If
dr.Close()
cmd_proc.Dispose()
Dim doc As New Document("C:\Temp\TestMerge6.docx")
doc.MailMerge.Execute(columnNames, values)
doc.Save(Response, "test_out.docx", ContentDisposition.Inline, Nothing)