We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Need help with Image insertion

I see you had an example for an image from an SQL stream, but I would like to get the image from the file system, with the filename stored in an SQL field. In my query which populates all necessary info for the merge, one of the fields is called SignatureFilename (in pink below). How can I pass that field value to the HandleMergeImageFieldFromBlob function and put the SignaturefileName value were usernamehere.jpg (in green below) appears.

Else If qExportTemplateID = “18” Then 'Word Needs Active Letter
Dim doc As New Document(“d:\templates\needsactiveletter.doc”)
Dim adapterTemplate1 As New SQLDataAdapter(“SELECT WUP.SignatureFileName FROM dbo.TableC”, myConnection)
Dim dtTemplate1 As New DataTable()
doc.MailMerge.FieldMergingCallback = New HandleMergeImageFieldFromBlob()
End If
pnlExport.Visible = True
End Sub

Private Class HandleMergeImageFieldFromBlob
Implements IFieldMergingCallback
Private Sub IFieldMergingCallback_FieldMerging(ByVal args As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging
End Sub
Private Sub ImageFieldMerging(ByVal e As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging

e.ImageFileName = System.IO.Path.Combine(“d:\hart11\signatures”, “usernamehere.jpg”)

End Sub
End Class


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try using the following code example:

Document doc = new Document("in.doc");

// Perform several mail merge operations populating only part of the document each time.

// Use DataTable as a data source.

DataTable resultsTable = GetInfo();

// Add FieldMergingCallback. It is needed to insert images upon mail merge.

doc.MailMerge.FieldMergingCallback = new MergeImageField();



private class MergeImageField : IFieldMergingCallback


void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)


// Do nothing.


void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)


string fileName = e.FieldValue.ToString();

e.ImageFileName = fileName;



private DataTable GetInfo()


// Create data table

DataTable table = new DataTable("Results");



// Add some dummy data.

table.Rows.Add(new object[] { "1", "C:\\Temp\\img1.jpg" });

table.Rows.Add(new object[] { "2", "C:\\Temp\\img2.jpg" });

table.Rows.Add(new object[] { "3", "C:\\Temp\\img3.jpg" });

return table;


The input and the output documents are attached.

Best regards,