ContentRange has a start and end
ContentPosition and those positions have parent
So, here is how you can get the location of your
DocumentModel document = DocumentModel.Load("input.docx");
ContentRange content = document.Content.Find("TOKEN").First();
Element start = content.Start.Parent;
Element end = content.End.Parent;
if (start == end)
Console.WriteLine(start.ElementType + " - " + end.ElementType);
start = start.Parent;
end = end.Parent;
while (start != null);
For a table with the
TOKEN text you would get this parents hierarchy:
Anyway, please take a look at Find and Replace examples, the second example shows how you can replace some placeholder text with a
However, instead of that have you considered using the mail merge feature?
Note, it can simplify this task for you, it can create a dynamic number of rows based on your collection of data. For instance, please check the Merge Ranges example.
I hope this helps.