Free Support Forum - aspose.com

Bookmarks and Inserting Merge Fields

I think I found a bug. I have bookmarks around the mergefield. Then I run a Mailmerge. Then I want to take the merged document and find the bookmarks to insert mergefields again. I can't seem to get it to work. Does anyone have code to do this?

Hello

Thanks for your request. Please try using the following code:

Document doc = new Document("C:\\Temp\\in.docx");

doc.MailMerge.Execute(new string[] {"Test"}, new string[] {"Value"});

// Save output document.

doc.Save("C:\\Temp\\out.docx");

Document doc2 = new Document("C:\\Temp\\out.docx");

DocumentBuilder builder = new DocumentBuilder(doc2);

builder.MoveToBookmark("MyBookmark");

// Insert MergeField

builder.InsertField("MERGEFIELD Test2");

// Save output document.

doc2.Save("C:\\Temp\\out2.docx");

Please see the attached documents.

Best regards,