Remove content control on image

Hi Aspose guys,

I used aspose to generate docx file. But, there are still content controls on images, text, tables,…
I wanna to remove all content controls, but keep content. For exanple, I wanna remove content control on an image but keep the image.
How aspose word do that? Please give me code example.

Thanks and regards,

Hi Vuong,

Thanks for your inquiry.
You can use following code snippet to remove SDTs from your document.

private void RemoveSdt(Document doc)
{
    // Get collection of SDT from the document
    NodeCollection nodes = doc.GetChildNodes(NodeType.StructuredDocumentTag, true, true);
    // Loop while there is SDT in the document
    while (nodes.Count> 0)
    {
        StructuredDocumentTag sdt = (StructuredDocumentTag) nodes[0];
        // Get parent node of SDT.
        // We should move all content from SDT to its parent to preserve documents content.
        CompositeNode parent = sdt.ParentNode;
        // Loop throuht all nodes inside SDT and move its convent to parent node
        while (sdt.HasChildNodes) parent.InsertBefore(sdt.FirstChild, sdt);
        // Remove SDT.
        sdt.Remove();
    }
}

In case of any ambiguity, please let me know.

Hi there,

Thanks for your inquiry.

Please see the code below to remove all content controls from a document.

foreach(StructuredDocumentTag tag in  doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
     tag.RemoveSelfOnly();

Thanks,

RemoveSelfOnly() removes the content in some instances. Not sure of the pattern.

Hi Henrik,

Thanks for your inquiry.

Could you please attach a template here which demonstrates the problem you are having?

Thanks,