Hi,
Hi Martin,
Thanks for your inquiry. Please use the StructuredDocumentTag.AppendChild method to add the specified node to the end of the list of child nodes for this node. See the following highlighted code snippet. Hope this helps you.
If you still face problem, please share your input document here for testing. I will investigate the issue and provide you more information about your query.
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (sdt.SdtType == SdtType.RichText)
{
sdt.RemoveAllChildren();
Paragraph para = new Paragraph(doc);
para.AppendChild(new Run(doc, "Some text"));
sdt.AppendChild(para);
}
}
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>
Hi,
string input = @“TestInput.docx”;
string output = @“TestOutput.docx”;
Document doc = new Document(input);
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (sdt.Tag != “RichContentControl”)
continue;
sdt.RemoveAllChildren();Paragraph para = new Paragraph(doc);para.AppendChild(new Run(doc, “some text”));sdt.AppendChild(para);
}
doc.Save(output);
Hi Martin,
Thanks for your inquiry. You can use following modified code example to update content control. This code works if content controls are not bound to CustomXML.
Document doc = new Document(MyDir + “TestInput.docx”);<o:p></o:p>
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (sdt.SdtType == SdtType.RichText)
{
if (sdt.Tag != "RichContentControl")
continue;
sdt.RemoveAllChildren();
Paragraph para = new Paragraph(doc);
para.AppendChild(new Run(doc, "New Rich text"));
sdt.AppendChild(para);
}
else if (sdt.SdtType == SdtType.PlainText)
{
Paragraph paragraph = (Paragraph)sdt.GetChild(NodeType.Paragraph, 0, true);
if (paragraph != null)
{
paragraph.RemoveAllChildren();
paragraph.AppendChild(new Run(doc, "**New Rich text"));
}
else
{
sdt.RemoveAllChildren();
sdt.AppendChild(new Run(doc, "**New plain text"));
}
}
}
doc.Save(MyDir + @"Out v16.10.0.docx");
The issues you have found earlier (filed as WORDSNET-4738) have been fixed in this Aspose.Words for .NET 17.5 update and this Aspose.Words for Java 17.5 update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(6)