We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Deleting Specific Region

Is it possible to delete a specific region (and all it’s contents)? I’ve got access to a MailMergeRegionInfo item so it seems like I ought to have everything I need to do so but I can’t figure it out.

The closest I’ve gotten is using the following code, but it doesn’t seem to remove everything:

var stopNode = region.EndField.Remove();
var currNode = region.StartField.Remove();
while (currNode != stopNode && currNode != null)
	var nextNode = currNode.NextSibling;
	currNode = nextNode;


Please bookmark the content and set its text to empty string to remove the content. We suggest you following solution:

  1. Move the cursor to the first field and insert BookmarkStart node.
  2. Move the cursor to the end field and insert BookmarkEnd node.
  3. Set the bookmark’s text to empty string using Bookmark.Text property.

Please read the following articles about working with bookmarks and navigation of cursor.
Working with Bookmarks
Navigation with Cursor

Hope this helps you.

Thank you, that was exactly what I needed.

For anyone else that may stumble across this in future, I ended up using the following:

MailMergeRegionInfo region = GetRegionThatNeedsRemoving();
var builder = new DocumentBuilder(_doc);
var guid = Guid.NewGuid().ToString();



_doc.Range.Bookmarks[guid].Text = "";


It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.