Mail Merge
- 3 minutes to read
This topic describes how to enable and use the Mail Merge feature in a WinForms or ASP.NET Web Forms application.
To enable Mail Merge, open the Application Designer and set the RichTextMailMergeDataType property to the type you use for storing the document templates.
You can use one of the following built-in types, depending on your ORM:
ORM | Business Object Type |
---|---|
XPO | DevExpress.Persistent.BaseImpl.RichTextMailMergeData |
Entity Framework | DevExpress.Persistent.BaseImpl.EF.RichTextMailMergeData |
Important
If you use Entity Framework Code First, register the DevExpress.Persistent.BaseImpl.EF.RichTextMailMergeData type in the DbContext (see Add a Class from the Business Class Library (EF)) before opening the Application Designer.
Run the application and invoke the Reports | Mail Merge Template navigation item to create new and access existing document templates.
You can use the Data Type property to specify the business class to be used as the document’s data source. In the Insert Merge Field dropdown (WinForms) and Insert Merge Field popup window (ASP.NET Web Forms), you can choose the Data Type’s fields to add to the document template.
Note
If the Data Type list does not show an item for your class, implement one of the following approaches:
- apply the VisibleInReportsAttribute (with the parameter set to true) or DefaultClassOptionsAttribute to the class;
- set the IModelClassReportsVisibility.IsVisibleInReports property of the corresponding BOModel | <Class> node to true.
The subfields are not displayed in Insert Merge Field, but you can type them manually: click Show All Field Codes and type the field using the { MERGEFIELD ObjectProperty.SubProperty }
notation.
Note
In ASP.NET Web Forms applications, create the INCLUDEPICTURE field and specify the name of a BLOB image property to include an image field in the document.
To view the records merged with the specified document template, select the required business objects in a List View (or open a single object’s Detail View) and click ShowInDocument. The ShowInDocument Action lets you view the records merged with the specified mail merge template directly from ListView.
Note
The ShowInDocument Action uses the in-place documents cache to generate and store the Action’s items. Note that this cache is not updated automatically. Refer to the InplaceDocumentCacheStorageBase class description for information on how to update this cache manually.