Enumerate and Modify MergeField content

4 posts, 0 answers
  1. Kadir
    Kadir avatar
    4 posts
    Member since:
    Feb 2011

    Posted 23 Feb Link to this post

    Hi,

    I want to enumerate and modify mergefields manually in a table, because Telerik is currently not supported nested mail merge (ref: https://feedback.telerik.com/Project/184/Feedback/Details/190035-wordsprocessing-nested-mail-merge)

     

    I found some code snippets similar to code below, but i can't find the FieldRangeStart type in the Word Processing Libraries for ASP.NET Ajax, seems it's works only WPF libraries? Isn't it?

     

    foreach (FieldRangeStart fieldStart in document.EnumerateChildrenOfType<FieldRangeStart>())
    {
        if (fieldStart.Field is MergeField)
        {
            mergeFields.Add(fieldStart);
        }
    }

     

    What do you suggest for enumerate and modify merge fields manually?

     

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1442 posts

    Posted 27 Feb Link to this post

    Hello Kadir,

    The FieldRangeStart object is part of the documentation model of the "RadRichTextBox for WPF" control. In the WordsProcessing library you can use the Field element in the EnumerateChildrenOfType<T>() method. Check more about the field types in the Fields section of the help documentation.

    Regards,
    Martin
    Telerik by Progress

  3. Kadir
    Kadir avatar
    4 posts
    Member since:
    Feb 2011

    Posted 28 Feb in reply to Martin Ivanov Link to this post

    Hi Martin,

    EnumerateChildrenOfType<T>() method not working with Field or MergeField types. Please see the attached image.

    By the way, "Fields" section, doesn't mention about the finding or enumerating existing fields, all examples related to inserting new field.

    Could yo provide, a working code sample?

  4. Tanya
    Admin
    Tanya avatar
    583 posts

    Posted 02 Mar Link to this post

    Hi Kadir,

    The EnumerateChildrenOfType() method works with elements inheriting the base DocumentElementBase class. To find the merge fields in a document, you will need to search for elements of type FieldCharacter, which have FieldCharacterType Start and their corresponding field is a MergeField. Here is a sample of how you can invoke the method to filter the fields:
    document.EnumerateChildrenOfType(Of FieldCharacter)().Where(Function(f) f.FieldCharacterType = FieldCharacterType.Start AndAlso TypeOf f.FieldInfo.Field Is MergeField)

    Hope this is helpful.

    Regards,
    Tanya
    Telerik by Progress

Back to Top