Exception giving value to a rich text control

I am having a problem trying to assign a text value to a Rich text control. I´m using Aspose.Words.dll version 15.3.0.

This is my code:

wordLicense = new License();
wordLicense.SetLicense(licensePath);

Document doc = new Document(templatePath);

foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (sdt.SdtType == SdtType.RichText)
    {
        if (sdt.Tag.Equals(field))
        {
            sdt.RemoveAllChildren();
            Paragraph para = new Paragraph(doc);
            Run r1 = new Run(doc);
            r1.Text = value;
            para.AppendChild(r1);
            sdt.AppendChild(para);
        }
    }
}

doc.Save(templatePath.Replace(".docx", ".pdf"));
doc = null;
wordLicense = null;

I receive an exception at sdt.AppendChild that reports:

System.ArgumentException: Cannot insert a node of this type at this location.

I attach the Word file.

Thank you.

Hi Fernando,

Thanks
for your inquiry. Please use following code example to achieve your requirements. Please read the detail of StructuredDocumentTag class from here:
https://reference.aspose.com/words/net/aspose.words.markup/structureddocumenttag/

Document doc = new Document(MyDir + "TestWordForm.docx");
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (sdt.SdtType == SdtType.RichText && sdt.Level == MarkupLevel.Inline)
    {
        if (sdt.Tag.Equals("Name"))
        {
            sdt.RemoveAllChildren();
            Run r1 = new Run(doc);
            r1.Text = "Name";
            sdt.AppendChild(r1);
        }
    }
}
doc.Save(MyDir + "Out.pdf");