List of MergeFields Present in a Bookmark

Hi Support,

  1. I have a document from which i have to get the list of the merge fields present under a bookmark.(i.e I have selected few merge fields and created a bookmark).

  2. Is there any mechanism in place to check if the word template is syntactically correct?

Thanks,

ValuePRO

Hi Piers,


Thanks for your inquiry.

1) You can get a list of MergeFields i.e. contained inside a bookmark by using the following code snippet:

Bookmark
bookmark = doc.Range.Bookmarks[“fromHere”];
ArrayList
list = ExtractSelectedContent.ExtractContent(bookmark.BookmarkStart,
bookmark.BookmarkEnd, false);
Paragraph
p = (Paragraph)list[0];

NodeCollection fieldStarts = p.GetChildNodes(NodeType.FieldStart,
true);
foreach (FieldStart fieldStart in
fieldStarts)
{
if
(fieldStart.FieldType.Equals(
FieldType.FieldMergeField))
{

}

}

Also, please visit the following link for a description of ExtractContent method:
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-extract-selected-content-between-nodes-in-a-document.html

2) If Aspose.Words encounters a problem that can be resolved upon loading a document, it recovers a document silently and does not throw any exceptions.

I hope, this will help.

Best Regards,

Thanks for quick reply. It worked