Reporting: Merging Images from Files Using SearchPath
Image placeholders in TX Text Control Reporting accept byte arrays, System.Drawing.Image objects, file paths, or Base64 strings at merge time. The MailMerge SearchPath property specifies the directory where referenced image files are located on disk during the merge process.

Merging images with Text Control Reporting is a very easy job: A placeholder is added at design-time to the template and merged with data from files, databases or memory.
The placeholder object gets a name that should match a data column in your data source. The data column must contain either the binary image data as a byte array, an object of type System.Drawing.Image, a file name, a hex or Base64 encoded string. These options cover most typical image representations in databases.
When the template designer TX Text Control Words is directly connected to a database to provide the proper field names, image placeholders can be directly bound to database fields using the context menu. But this article shows what happends behind the scenes and how to use the SearchPath property of MailMerge to define the image location.
Consider the following XML file as the data source for our merge process:
<?xml version="1.0" encoding="utf-8" ?>
<report>
<customer>
<company>Microsoft Corporation</company>
<company_logo>microsoft_logo.png</company_logo>
</customer>
<customer>
<company>Text Control, LLC</company>
<company_logo>textcontrol_logo.png</company_logo>
</customer>
</report>
Each customer entry has two fields: The company name and the file name of a company logo.
In order to create a very simple template for this data source, the following steps are required.
-
Open TX Text Control Words and click the Insert Merge Field button (make sure that you don't open the drop-down button) from the Mailings ribbon tab.
In the opened dialog box, type in the name of the first field "company" into the Name text box and confirm with OK.

-
Now, choose Image Placeholder from the Image drop-down button in the Insert ribbon tab. Resize the object to your desired dimension.

-
Right-click the image, and choose Edit Object Name... from the context menu.

-
In the opened dialog box, type in the name of the image field in our data source company_logo and confirm with OK.
Given that you created a .NET application and connected an instance of MailMerge with TextControl as described in our quick start tutorial, you can use the SearchPath property to define the location of the images.
-
Open the properties Windows of MailMerge, find the SearchPath property and type in the location of your images.

In this example, TX Text Control is trying to load the images from these locations:
- C:\Users\Pictures\microsoft_logo.png
- C:\Users\Pictures\textcontrol_logo.png
If the SearchPath is empty, the images are expected to be located in the application's root folder.
You can download this simple Visual Studio project and test it on your own. All you need is a trial version of TX Text Control .NET for Windows Forms or TX Text Control Server for ASP.NET. If your run the sample and choose Merge from the Report main menu, you will see the results shown below:

Reporting
The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.
Related Posts
Creating Your First ASP.NET Reporting Application
The MailMerge and ServerTextControl components of TX Text Control .NET Server for ASP.NET enable server-side reporting in Web Forms. A template.docx merges with XML data via a button click…
New Online Sample: Build your First Report
A new interactive online demo walks through building a report with TX Text Control in three steps: preparing JSON data in a live editor, creating a template with merge fields and repeating blocks,…
ReportingDocumentationReportingCloud
Create your First Document with ReportingCloud
ReportingCloud documentation now includes interactive tutorials for creating documents without code. Users enter an API key, choose a format such as PDF or DOCX, customize the merge data payload,…
MailMerge: Starting Each Merge Block on a New Page
Merge blocks in TX Text Control repeat based on matching data rows. Applying ParagraphFormat.PageBreakBefore to the first paragraph of a block forces each repetition onto a new page. Section…
Using MailMerge with JSON Data
Merge document templates with JSON data using TX Text Control MailMerge by converting nested JSON strings into DataSet objects via Newtonsoft.Json. The JSON is first transformed to XML, then…
