I am currently working on a project that will allow a customer to upload Word docs to a known directory, pull the mail-merge fields from the doc, and store the mail-merge fields in a database. I have a process that will kick off at the end of a business day to create mail-merged documents with the mail-merge fields in the database and data from the current day’s processing. This is currently possible with Microsoft’s mail-merge control, and I was curious if you had an example with your mail-merge control.
Thanks for your inquiry. Please use the MailMerge.GetFieldNames method to get collection of mail merge field names available in the document and save these field names to database.
Document doc = new Document(MyDir + "MailMergeSection.doc");
// returns a collection of mail merge field names available in the document.
string[] fieldnames = doc.MailMerge.GetFieldNames();
// save fields to database
....
....
....
// insert fields to new document
Document doc2 = new Document();
DocumentBuilder builder = new DocumentBuilder(doc2);
foreach (string fname in fieldnames)
{
// Inserts a Word field into a document and updates the field result.
builder.InsertField(@"MERGEFIELD "+fname+" \\* MERGEFORMAT");
builder.Writeln();
}
doc2.Save(MyDir + "out.docx");