We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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)<o:p></o:p>

{<o:p></o:p>

// Get collection of SDT from the document<o:p></o:p>

NodeCollection nodes = doc.GetChildNodes(NodeType.StructuredDocumentTag, true, true);<o:p></o:p>

// Loop while there is SDT in the document<o:p></o:p>

while (nodes.Count > 0)<o:p></o:p>

{<o:p></o:p>

StructuredDocumentTag sdt = (StructuredDocumentTag)nodes[0];<o:p></o:p>

// Get parent node of SDT.<o:p></o:p>

// We should move all content from SDT to its parent to preserve documents content.<o:p></o:p>

CompositeNode parent = sdt.ParentNode;<o:p></o:p>

// Loop throuht all nodes inside SDT and move its convent to parent node<o:p></o:p>

while (sdt.HasChildNodes) parent.InsertBefore(sdt.FirstChild, sdt);<o:p></o:p>

//Remove SDT.<o:p></o:p>

sdt.Remove();<o:p></o:p>

}<o:p></o:p>

}


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.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:blue;mso-no-proof:yes”>foreach<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> (StructuredDocumentTag tag in
doc.GetChildNodes(NodeType.StructuredDocumentTag,
true))<o:p></o:p>

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,