Best way to find shapes in Word doc

Hello all,

I am working on a small method to throw a flag when a Word document has shapes in it. I already have a method that uses the LayoutEnumerator class to list everything in the document.

The best way of finding shapes I have right now is to get the kind of the LayoutEnumerator.

For example:

LayoutEnumerator e = new LayoutEnumerator(doc);

if(e.Kind == "SHAPE") //do something;

This doesn't get me far because a lot of things are also considered shapes. Also, 'if(e.Type == ShapeType.Line)' doesn't work either.

Does anybody know what is the best way I could find shapes in a document?

Thanks.

Hi Erwin,


Thanks for your inquiry. The Shape class represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture. Here is how you can get all shapes from the document node, but you can do this for any smaller node too, for example get shapes from a single section or a paragraph.

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

There could also be group shapes, they have different node type and here is the code to retrieve all such group shape from document.

NodeCollection groupShapes = doc.GetChildNodes(NodeType.GroupShape, true);

You can then set the value of flag based on the groupShapes.Count property. Please let me know if I can be of any further assistance.

Best regards,