Free Support Forum -

IncludePicuture Event Handler not working

In Word we have used the IncludePicture with Mail Merge to dynamically change images when generating documents. We have tried the examples with Aspose 11.8 but the event handler does not fire and the documentBuilder does not merge the image.

Can you help us get past this issue? I'm uploading a test application we built which uses an xml file as the data source for the Word doc (template). The application will save the merged document as a new file.


Hi William,

Thanks for your inquiry. You are using MailMerge field inside IncludePicture field. In this case, you need to use LoadOptions.PreserveIncludePictureField property. Please write your code inside IFieldMergingCallback.FieldMerging and check following code snippet for your kind reference.

LoadOptions lo = new LoadOptions();

lo.PreserveIncludePictureField = true;

Document doc = new Document(MyDir + "in.docx", lo);

Image image = Image.FromFile(@"D:\\Aspose.jpg");

MemoryStream stream = new MemoryStream();

image.Save(stream, ImageFormat.Bmp);

String[] fieldNames = new String[] { "picMailMerge" };

Object[] fieldValues = new Object[] { stream, };

IncludePicture obj = new IncludePicture();

doc.MailMerge.FieldMergingCallback = obj;

doc.MailMerge.Execute(fieldNames, fieldValues);

doc.Save(MyDir + "AsposeOut.docx");

public class IncludePicture : IFieldMergingCallback


public ArrayList nodes = new ArrayList();

void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)


if (args.FieldName.Equals("picMailMerge"))


//Your Code



void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)




Please let us know if you have any more queries.