Content control (SDT) getting null

Hello Team,
I have a Word document with one content control (STD), but when I attempt to retrieve a list of content controls (SDT), I get a null result. How can I resolve this issue?

Snippet :
var sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);

Attachment :
SDT_Issue.docx (27.5 KB)

Thanks,
Alpesh Chaudhari

@AlpeshChaudhariDev This is not a bug. In Aspose.Words document object model structured document tag cannot contain section break. In this case special nodes are used to mark range of structured document tag spanned several section - StructuredDocumentTagRangeStart and StructuredDocumentTagRangeEnd.

1 Like

Thanks… @alexey.noskov

1 Like

Could you please provide information about the tools that are visible in the screenshot above?

@AlpeshChaudhariDev This is Aspose.Words DocumentExplorer demo application. It demonstrates how the document is represented in Aspose.Words DOM.

Okay, thank you for providing me with helpful information

1 Like

Hello team,
Can I convert the StructuredDocumentTagRangeStart and StructuredDocumentTagRangeEnd to StructuredDocumentTag ? When I convert a Word document to HTML, I am unable to identify the content control (SDT) in the HTML output.

@AlpeshChaudhariDev The problem occurs because multi-section SDT are not currently supported upon exporting document to HTML. This feature request is already logged as WORDSNET-26147.

In Aspose.Words document object model structured document tag cannot contain section break. In this case special nodes are used to mark range of structured document tag spanned several section - StructuredDocumentTagRangeStart and StructuredDocumentTagRangeEnd.
As a workaround you can remove section breaks in your document (join sections).

Document doc = new Document("C:\\Temp\\in.docx");
// join sections in the document
while (doc.Sections.Count > 1)
{
    doc.FirstSection.AppendContent(doc.Sections[1]);
    doc.Sections[1].Remove();
}

// Save/open the document in DOCX format to apply changes.
using (MemoryStream tmpStream = new MemoryStream())
{
    doc.Save(tmpStream, SaveFormat.Docx);
    tmpStream.Position = 0;
    doc = new Document(tmpStream);

}

doc.Save("C:\\Temp\\out.html");