Remove image from Picture Content Control


How can i remove the image from a Picture Content Control but keep the control in the document ???


Hi Kevin,

Thanks for your inquiry. The StructuredDocumentTag Class represents a structured document tag (SDT or content control) in a document. The picture contents control fills the content control with a single picture.

Please note that Aspose.Words tries to mimic the save behavior as MS Word do. You cannot remove image from picture contents control and keep the picture content control. If you remove image from picture contents control by using MS Word, the empty picture template will exist in the document. Please see the attached image for detail

However, you can set picture contents control data with an empty/template picture by using following code snippet.

Document document = new Document(MyDir + "in.docx");
NodeCollection sdtNodes = document.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach(StructuredDocumentTag sdt in sdtNodes)
    if (sdt.SdtType == SdtType.Picture)
        DrawingML dml = (DrawingML) sdt.GetChild(NodeType.DrawingML, 0, true);
        if (dml.HasImage)
            dml.ImageData.SetImage(MyDir + "Empty Picture");