Free Support Forum - aspose.com

Deleting a Slide by Its ID

I have been trying to code something that can reference a slide by its ID and then remove it from the presentation.


My problem seems to be that calling GetSlideById returns a BaseSlide object but then the Remove function seems to require an ISlide object.

base_slide = pres.GetSlideById(476);
pres.Slides.Remove(base_slide);

Any help someone can provide would be much appreciated.

Thanks

Hi Kevin,


I have observed your comments. I request to you please follow guidelines on this link. I hope this link will help you to achieve your requirements.

Best Regards,

Thank you for your response.


I had been looking at that same page but the issue is that it is using the slide index to return the ISlide reference. I was looking to be able to use the SlideId property to reference a slide and then remove it. Is that possible?

Big picture I am looking to remove a number of slides from a PowerPoint file but I’ve found that using the index of the slide gets confusing after you start removing slides since the index seems to change.

Thanks

Hi Kevin,


I have shared a code snippet with you. I hope this will help you to achieve your requirements.

static void Main(string[] args)

{


Presentation pres=new Presentation(“test.pptx”);


uint id=0;


pres.Slides.Remove((ISlide)pres.GetSlideById(id));


}

}

}

Best Regards,

That worked perfectly. Thank you so much Muhammad.