Skip to content
.NET, WinForms, XtraRichEdit
C#
Branch: 13.1.4+
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CS Source auto update [skip ci] Nov 9, 2018
VB Source auto update [skip ci] Nov 9, 2018
.gitattributes
.gitignore initial commit Apr 23, 2018
LICENSE initial commit Apr 23, 2018
Readme.md add file list to readme Nov 15, 2018
config.json initial commit Apr 23, 2018

Readme.md

Files to look at:

How to use images when implementing the mail-merge functionality

This example illustrates how to embed an image into a merge template item when implementing mail-merge.

Generally, a mail-merge template document consists of static text and several MERGEFIELD fields. However, these fields allow you to merge only textual content into a resulting document. If you wish to add images that are contained in the datasource, define the INCLUDEPICTURE fields somewhere in the template. Here we face a problem because by default an argument specified in the INCLUDEPICTURE field is treated as an URI of an external file. However, we might need to use this parameter differently. For instance, in this particular example we use it to load an image from a database. To implement this custom image extraction mechanism, we need to create and register a custom IUriStreamService Interface before calling the RichEditControl.MailMerge Method. The IUriStreamService.GetStream Method of this interface will receive an argument specified in the INCLUDEPICTURE field and return an appropriate image stream (we should prepare it based on the passed argument). The last problem we have is how to define an argument so that each merged template item will receive an appropriate image according to the currently merged record. The solution is to use some unique identifier. We just need to define a nested MERGEFIELD in INCLUDEPICTURE for this purpose:

{ INCLUDEPICTURE "dbimg://{ MERGEFIELD CategoryID }" }

So, during the mail-merge operation, the IUriStreamProvider.GetStream() method will receive a parameter in the form "dbimg://", where corresponds to the currently merged record. Thus, we can look up an appropriate image in the datasource (it is passed to the IUriStreamProvider implementor's constructor in this example) by using this value.

Note that the same approach is illustrated in the "Merge Database Records" demo module (see Demos in Installation). However, we decided to prepare a separate standalone example because understanding of this concept might be not very easy for some of our customers in the context of a complicated demo application.

To test this example locally, setup a sample "Northwind" database (you can download it from the Master-Detail Mail Merge essential - The simplest implementation code example) in your SQL Server instance.

See Also:
Utility for creating a Mail Merge template
How to create nested fields programmatically
How to import HTML files containing images referenced using custom prefix


You can’t perform that action at this time.