For the mail merge feature to work you should load a data source into the rich text document's mail merge object. The code below demonstrates how to load a CSV file embedded as a resource and set some field mappings:
Load Mail Merge Data Source |
Copy Code
|
---|---|
// Load a mail merge data source from resource Stream stream = NResources.Instance.GetResourceStream("RSTR_Employees_csv"); NDataSource dataSource = NDataSourceFormat.Csv.LoadFromStream(stream, new NDataSourceLoadSettings(null, null, true)); // Create the field mappings NMailMergeFieldMap fieldMap = new NMailMergeFieldMap(); fieldMap.Set(ENMailMergeDataField.CourtesyTitle, "TitleOfCourtesy"); fieldMap.Set(ENMailMergeDataField.FirstName, "FirstName"); fieldMap.Set(ENMailMergeDataField.LastName, "LastName"); fieldMap.Set(ENMailMergeDataField.City, "City"); dataSource.FieldMap = fieldMap; documentBlock.MailMerge.DataSource = dataSource; |