This is a migrated thread and some comments may be shown as answers.

Enumerate and Modify MergeField content

3 Answers 245 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Kadir
Top achievements
Rank 1
Kadir asked on 23 Feb 2017, 06:47 AM

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?

 

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 27 Feb 2017, 02:06 PM
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

0
Kadir
Top achievements
Rank 1
answered on 28 Feb 2017, 09:09 AM

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?

0
Tanya
Telerik team
answered on 02 Mar 2017, 02:26 PM
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

Tags
WordsProcessing
Asked by
Kadir
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Kadir
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or