We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to change Text one a single Content Control when there are duplicates?

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);
    }

Actually ignore this, I’m being silly (really not feeling well and that’s my excuse!), I can just add a break or handle them differently (e.g. pass in a list of textValues and add a loop and change them one by one).

@SCDGLC,

It is great that you will be able to resolve this issue on your end. Please let us know any time you have any further queries.