This question is locked. New answers and comments are not allowed.
I want to traverse a document and programatically insert merge fields at specific locations.
Below I wrote some code that does traverse the document, but InsertField always inserts the merge filed at the document start. Pos is being moved but it seems the radeditor document caret pos is not.
How can I move the caret position of the rededitor to match where the documnetposition class is positioned?
Also I want to replace keywords in my document with the merge fields, so how do I delete the current word?
Code:
Using reader As New StreamReader(fs) Dim s As String = reader.ReadToEnd Dim provider_xaml As New Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider Dim radEditor As New Telerik.Windows.Documents.Model.RadDocumentEditor(provider_xaml.Import(s)) Dim pos As New Telerik.Windows.Documents.DocumentPosition(radEditor.Document) pos.MoveToFirstPositionInDocument() Do Until Telerik.Windows.Documents.DocumentPosition.IsAtDocumentEnd(pos) pos.MoveToNextWordStart() Dim w As String = pos.GetCurrentSpanBox.Text If w.StartsWith("&") Then Dim field As New Telerik.Windows.Documents.Model.MergeField field.DisplayMode = Telerik.Windows.Documents.Model.FieldDisplayMode.Code field.PropertyPath = "Name" radEditor.InsertField(field) End If LoopEnd Using