NodeRemove Method
Removes itself from the parent.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
public void Remove()
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.OfType<Shape>())
    // Several shape types can have an image including image shapes and OLE objects.
    if (shape.HasImage)

// Now we can delete shapes.
foreach (Shape shape in shapesToDelete)
Shows how to remove all nodes of a specific type from a composite node. In this example we remove tables from a section body.

// Get the section that we want to work on.
Section section = doc.Sections[0];
Body body = section.Body;

// Select the first child node in the body.
Node curNode = body.FirstChild;

while (curNode != null)
    // Save the pointer to the next sibling node because if the current 
    // node is removed from the parent in the next step, we will have 
    // no way of finding the next node to continue the loop.
    Node nextNode = curNode.NextSibling;

    // A section body can contain Paragraph and Table nodes.
    // If the node is a Table, remove it from the parent.
    if (curNode.NodeType.Equals(NodeType.Table))

    // Continue going through child nodes until null (no more siblings) is reached.
    curNode = nextNode;
See Also