Error “cannot insert a node of this type at this location” is shown when changing value for content control of type rich text box with Level = MarkupLevel.Inline. Please see more details in the attachment.
if (sdt.Level == MarkupLevel.Inline && string.Equals(sdt.Title, “ANNEX_INSTRUMENT”, StringComparison.InvariantCultureIgnoreCase))
{
sdt.RemoveAllChildren();
Paragraph para1 = new Paragraph(doc);
Run run1 = new Run(doc);
run1.Text = txtText.Text;
para1.Runs.Add(run1);
sdt.ChildNodes.Add(para1); => error with this line.
}
Hi there,
Document doc = new Document(wordFilePath);<o:p></o:p>
if (doc != null)
{
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (sdt.SdtType == SdtType.RichText)
{
if (sdt.Level == MarkupLevel.Block && string.IsNullOrWhiteSpace(sdt.Title))
{
sdt.RemoveAllChildren();
Paragraph para1 = new Paragraph(doc);
Run run1 = new Run(doc);
run1.Text = txtText.Text;
para1.Runs.Add(run1);
sdt.ChildNodes.Add(para1);
}
if (sdt.Level == MarkupLevel.Inline && string.Equals(sdt.Title, "ANNEX_INSTRUMENT", StringComparison.InvariantCultureIgnoreCase))
{
sdt.RemoveAllChildren();
Run run1 = new Run(doc);
run1.Text = txtText.Text;
sdt.ChildNodes.Add(run1);
}
}
}
}
doc.Save(outputPath);
Thank you for your answer, Tahir.
It helps me to solve the issue.
Hi there,