We have an existing SDT workflow we’d like to use Aspose to improve, if possible.
I’m having difficulty inserting HTML into a SDT tag.
I’ve attached an entire free-standing demo project, including a sample .docx file, but the key code that’s failing goes like this:
///
/// Set a simple SDT text field using plain text
///
private static void SetSdtHtmlText(Document doc, StructuredDocumentTag sdtToChange, string htmlForSdt)
{
// Check.EnsureNotNull(doc);
// Check.EnsureNotNull(sdtToChange);
// Reset IsShowingPlaceholderText to hide placeholder text.
sdtToChange.IsShowingPlaceholderText = false;
// Null fields are just blank
htmlForSdt = htmlForSdt ?? string.Empty;
var tmpParagraph = new Paragraph(doc);
var tmpRun = new Run(doc);
tmpParagraph.AppendChild(tmpRun);
sdtToChange.RemoveAllChildren();
// DOES NOT WORK
sdtToChange.AppendChild(tmpParagraph);
// We need to use Document Builder to insert HTML.
var tmpDocBuilder = new DocumentBuilder(doc);
tmpDocBuilder.MoveTo(tmpParagraph);
tmpDocBuilder.InsertHtml(htmlForSdt);
}
This gives me a “Cannot insert a node of this type at this location.” error.
There are a other posts in this area, but none of them have helped me figure out what to do here.
All help appreciated