Iterating through Bookmarks/FormFields

2 posts, 0 answers
  1. Lagrange
    Lagrange avatar
    16 posts
    Member since:
    Sep 2010

    Posted 21 May 2015 Link to this post


    I'm evaluating the Telerik.Windows.Documents API, to replace Aspose.NET in our app, for costs reason.

    One of our main need, is to open existing .docx files, and replace all bookmark and formFields in the model, by business values.

    I don't find any way to iterate through bookmarks and Fields. The EnumerateChildrenOfType is not usable, as Bookmark didn't inherit from DocumentElementBase.

    Aspose allow it with "Document.Range.Bookmarks.Cast<Bookmark>()", can you provide an example or an equivalent ?


    Romain Lagrange

  2. Tanya
    Tanya avatar
    575 posts

    Posted 22 May 2015 Link to this post

    Hi Lagrange,

    Thank you for contacting Telerik support.

    The Bookmark itself is represented as a pair of BookmarkRangeStart and BookmarkRangeEnd objects. You could obtain all the BookmarkRangeStart elements using the EnumerateChildrenOfType() method:
    IEnumerable<BookmarkRangeStart> bookmarks = document.EnumerateChildrenOfType<BookmarkRangeStart>();

    The next snippet is demonstrating how you could insert text in a Bookmark:
    BookmarkRangeStart first = bookmarks.First();
    int index = first.Paragraph.Inlines.IndexOf(first);
    first.Paragraph.Inlines.Insert(index + 1, new Run(document) { Text = "In bookmark" });

    For more information about Bookmarks you could refer to our documentation on the matter.

    The form fields are not supported in RadWordsProcessing. We have already logged this request and you could vote and subscribe to the related public item in the feedback portal in order to receive updates about any status changes on it.

    Hope this information is useful.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top