How to remove content controls

Hi,

I have docx files which include content controls. How do I remove them but keep the text/images of these control? By this way, when users open docx files, they just see normal documents without content controls.

I appreciate for your helps.

Regards,

Vu

Hi
Thanks for your request. You can try using code like the following to remove SDTs from your document.

///
/// Removes all SDT nodes from the docuemnt, preserving content
///
/// Input 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();
    }
}

Please let us know in case of any issues, we are always glad to assist you.
Best regards,