I have a Word document where I have Content Controls with the same Tag and Title (i.e. duplicates) and I want to add different Text values to each of them. This is my current code but it changes the Text of all of the duplicate Content Controls.
private static void WriteSingleValue(string contentControlTag, string contentControlTitle, string textValue, string filenameAndPath)
{
Document doc = new Document(filenameAndPath);
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (sdt.Tag == contentControlTag & sdt.Title == contentControlTitle)
{
sdt.RemoveAllChildren();
Run run = new Run(doc, textValue);
run.Font.Name = "Arial";
run.Font.Size = 10;
sdt.AppendChild(run);
}
}
doc.Save(filenameAndPath);
}