Updating/Deleting Individual MailMerge Fields with MergeFieldEventHandler

Hello,

I am evaluating the aspose.word product and it is very close to satifying all of my requirements.

I do have a question regarding updating/deleting individual mail merge fields which have already been added to a document. Do you have any examples of how I can do this? Can this be done through the MergeFieldEventHandler somehow? If so, I’d appreciate any guidance. Thanks!

The easiest way to update merge fields individually is to use DocumentBuilder.MoveToMergeField method. Note that just calling this method moves the cursor and deletes the merge field. So if you wanted to delete the field you don’t need to do anything else. If you want to insert something, use any of the DocumentBuilder methods to insert content and formatting there.

If you are inside MergeFieldEventHandler, you can set e.Text = “” and the mail merge engine will insert this empty string into the document in place of the merge field.

Thanks Roman, that worked great. One more question... after I make the modifications, it is possible to save the document on the server without the user having to view it, save it, and upload it?

Sure, just use one of Document.Save overloads that do not send to the browser, but save to a file or to a stream.