public void DeleteAllImages()
{
Document doc = new Document(MyDir + "Image.SampleImages.doc");
Assert.AreEqual(6, doc.GetChildNodes(NodeType.Shape, true).Count);
//ExStart
//ExFor:Shape.HasImage
//ExFor:Node.Remove
//ExSummary:Shows how to delete all images from a document.
// Here we get all shapes from the document node, but you can do this for any smaller
// node too, for example delete shapes from a single section or a paragraph.
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
// We cannot delete shape nodes while we enumerate through the collection.
// One solution is to add nodes that we want to delete to a temporary array and delete afterwards.
ArrayList shapesToDelete = new ArrayList();
foreach (Shape shape in shapes)
{
// Several shape types can have an image including image shapes and OLE objects.
if (shape.HasImage)
shapesToDelete.Add(shape);
}
// Now we can delete shapes.
foreach (Shape shape in shapesToDelete)
shape.Remove();
//ExEnd
Assert.AreEqual(1, doc.GetChildNodes(NodeType.Shape, true).Count);
doc.Save(MyDir + @"\Artifacts\Image.DeleteAllImages.doc");
}