ImageFieldMergingArgsImage Property
Specifies the image that the mail merge engine must insert into the document.

Namespace: Aspose.Words.MailMerging
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 20.1
public Image Image { get; set; }

Property Value

Type: Image
Shows how to set which images to merge during the mail merge.
public void MergeFieldImages()
    Document doc = new Document();

    // Insert a merge field where images will be placed during the mail merge
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.InsertField("MERGEFIELD Image:ImageColumn");

    // When we merge images, our data table will normally have the full e. of the images we wish to merge
    // If this is cumbersome, we can move image filename logic to another place and populate the data table with just shorthands for images
    DataTable dataTable = CreateDataTable("Images", "ImageColumn",
        new string[]
            "Aspose logo",
            ".Net logo",

    // A custom merging callback will contain filenames that our shorthands will refer to
    doc.MailMerge.FieldMergingCallback = new ImageFilenameCallback();

    doc.Save(ArtifactsDir + "Field.MergeFieldImages.docx");

/// <summary>
/// Image merging callback that pairs image shorthand names with filenames.
/// </summary>
private class ImageFilenameCallback : IFieldMergingCallback
    public ImageFilenameCallback()
        mImageFilenames = new Dictionary<string, string>();
        mImageFilenames.Add("Aspose logo", ImageDir + "Aspose.Words.gif");
        mImageFilenames.Add(".Net logo", ImageDir + "dotnet-logo.png");
        mImageFilenames.Add("Watermark", ImageDir + "Watermark.png");

    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
        throw new NotImplementedException();

    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
        if (mImageFilenames.ContainsKey(e.FieldValue.ToString()))
            #if NETFRAMEWORK
            e.Image = Image.FromFile(mImageFilenames[e.FieldValue.ToString()]);
            e.Image = SKBitmap.Decode(mImageFilenames[e.FieldValue.ToString()]);
            e.ImageFileName = mImageFilenames[e.FieldValue.ToString()];


    private readonly Dictionary<string, string> mImageFilenames;
See Also