Getting the relationship ID of a shape via looking for their names (PowerPoint) RRS feed

  • Question

  • Hey there,

    how can I get the relationship ID of a shape through their name? What I want to do is something like this:

    	public static String GetShapeRId (Slide slide, String name)
    		foreach (Shape shape in shapes)
    			if (shape.NonVisualShapeProperties.NonVisualDrawingProperties.Name == name)
    				return shape.RelationshipID; // This is the part I am looking for.
    		return null;
    I am quite new to C# and OpenXML so as always suggestions for code improvements would be appreciated as well.
    Friday, August 5, 2016 8:18 AM


  • Hi,

    What do you mean the relationship ID of shapes?

    Is it the id value of a shape as shown below?



        <p:cNvPr id="3" name="Content Placeholder 2" />


          <a:spLocks noGrp="1" xmlns:a="" />



          <p:ph idx="1" />





    return shape.NonVisualShapeProperties.NonVisualDrawingProperties.Id



     string docName = (@"C:\Users\Administrator\Desktop\Presentation1.pptx");
                using (PresentationDocument ppt = PresentationDocument.Open(docName, false))
                    PresentationPart pptPart = ppt.PresentationPart;
                    foreach (SlidePart slide in pptPart.SlideParts)
                        ShapeTree shapes = slide.Slide.CommonSlideData.ShapeTree;
                        foreach (Shape shape in shapes.Elements<Shape>())
                            if (shape.NonVisualShapeProperties.NonVisualDrawingProperties.Name == "Content Placeholder 2")

    Monday, August 8, 2016 5:51 AM