Reputation: 3001
I have am manipulating a Power Point slide using OpenXML SDK. The slide has one image on it. What I am trying to do is if a particular image is found on the server replace the slides image with the one found on the server, otherwise delete the image completely.
I have the replacement working fine but if I try to delete the image I still get an image control with "This image can not be displayed" in it.
Here is what I am doing to delete the image, note slidePart is the slide I am manipulating:
'get the first image on the slide
Dim blip As Drawing.Blip = slidePart.Slide.Descendants(Of Drawing.Blip)().First()
blip.Remove()
slidePart.Slide.Save()
Could anyone tell me what I am doing wrong? Any advice would be appreciated, thanks much.
Upvotes: 1
Views: 2580
Reputation: 15401
You want to look for the Picture
element that corresponds to your image and delete that element. I tend to search by the image name in order to find the Picture
element and then just delete it. Here's a C# sample of the code I use:
Picture imageToRemove = slidePart.Slide.Descendants<Picture>().SingleOrDefault(picture => picture.NonVisualPictureProperties.OuterXml.Contains(imageFileName));
if (imageToRemove != null)
{
imageToRemove.Remove();
}
Upvotes: 2