Updating Content Control - Cannot insert node of this type at this location

Hi,

I’m just trying to change the text value of a content control - using the Aspose.Words 18.2.0 in .NET core.

The following excerpt form the documentation throws an error: Cannot insert node of this type at this location

foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (sdt.SdtType == SdtType.PlainText)
{
sdt.RemoveAllChildren();
Paragraph para = sdt.AppendChild(new Paragraph(doc)) as Paragraph; <>
Run run = new Run(doc, “new text goes here”);
para.AppendChild(run);
}
}

Please assist, I’m just trying to replace the text in a plain text content control.

@alexmalbon,

Thanks for your inquiry. Instead of Paragraph, you need to append Run node(s) as direct child of content control that has type PlainText. Hope this helps you.

Thanks for getting back to me @tahir.manzoor

I tried that and it didn’t work - turns out that the data inside the content control was actually stored in a document property, so updating it there was the right thing to do.

doc.BuiltInDocumentProperties.Title = “My New Title Here”

@alexmalbon,

Thanks for your inquiry. Please ZIP and attach your input and expected output Word documents here for our reference. We will then provide you more information about your query along with code.

A post was merged into an existing topic: How to add paragraph to STRUCTURED_DOCUMENT_TAG