MailMergerContext.SetSimpleDataSource

MailMergerContext SetSimpleDataSource method. Sets data source used to execute simple mail merge.

SetSimpleDataSource(string[], object[])

Sets data source used to execute simple mail merge.

public void SetSimpleDataSource(string[] fieldNames, object[] fieldValues)

Remarks

If both simple mail merge data source and data source for mail merge with regions are specified, mail merge with regions is executed first and then simple mail merge is executed.

Examples

Shows how to fill a template with data by executing mail merge with regions and simple mail merge using fluent API.

string[] names = new string[] { "FirstName", "SecondName", "Position" };
string[] values = new string[] { "James", "Bond", "Spy" };

DataTable dt = new DataTable("Items");
dt.Columns.Add("Item");
dt.Columns.Add("Quantity");
dt.Columns.Add("Price");
dt.Rows.Add("Orange", 5, 10);
dt.Rows.Add("Apple", 10, 4);
dt.Rows.Add(null, null, null); // empty row.
dt.Rows.Add("Pear", 4, 6);

MailMergerContext context = new MailMergerContext();
context.MailMergeOptions.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyTableRows;
context.SetSimpleDataSource(names, values);
context.SetRegionsDataSource(dt);

MailMerger.Create(context)
    .From(MyDir + "MailMergeTemplate.docx")
    .To(ArtifactsDir + "MailMergerContext.docx")
    .Execute();

See Also


SetSimpleDataSource(DataRow)

Sets data source used to execute simple mail merge.

public void SetSimpleDataSource(DataRow dataRow)

Remarks

If both simple mail merge data source and data source for mail merge with regions are specified, mail merge with regions is executed first and then simple mail merge is executed.

See Also


SetSimpleDataSource(DataTable)

Sets data source used to execute simple mail merge.

public void SetSimpleDataSource(DataTable dataTable)

Remarks

If both simple mail merge data source and data source for mail merge with regions are specified, mail merge with regions is executed first and then simple mail merge is executed.

See Also