Free Support Forum -

Insert an image before/after a shape


I have a source document that includes a shape with special names (example: shape1, shape2, ...). I want to insert an image before and after this shapes.

It is looks like: picb1shape1pica1....picb2shape2pica2...

I can not use a bookmark to mark a shape or place where I need to add an image.

How can I find the begin and the end of the shape and insert an image?


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can loop through all shapes in your document, check shape’s names and insert your additional shapes where it is required. For example, see the following code:

// Open document.

Document doc = new Document(@"Test001\in.doc");

// Get array of shapes.

Node[] shapes = doc.GetChildNodes(NodeType.Shape, true).ToArray();

// Create shape which should be inseted before and after (I will insert the same shape, you can insert different).

Shape addShape = new Shape(doc, ShapeType.Ellipse);

addShape.FillColor = Color.Red;

addShape.Width = 20;

addShape.Height = 20;

addShape.WrapType = WrapType.Inline;

// Lopp throug all shapes.

foreach (Shape shape in shapes)


// Check name of the shape.

if(shape.Name == "myShape")


// insert copy of the additioanal shape before and after current shape.

shape.ParentNode.InsertAfter(addShape.Clone(true), shape);

shape.ParentNode.InsertBefore(addShape.Clone(true), shape);



// Save output document.


Hope this helps.

Best regards.