In scenarios such as automating PPT template processing, batch-organizing slides, and dynamically adjusting page order, you often need to manage the slides themselves: adding, deleting, copying, and showing or hiding them. This article shows how to perform these slide-management operations using the Free Spire.Presentation for .NET library, with no Office dependency required.
The free version can create and modify PPT/PPTX files, but note that the total number of slides in a document cannot exceed 10 when reading or writing files. It is therefore suitable for small- to medium-sized workloads.
Environment Setup and Core Objects
Install via NuGet:
dotnet add package FreeSpire.Presentation The namespace is Spire.Presentation. Slide management revolves around two core types: Presentation is the entry point for the entire presentation, and Presentation.Slides is the slide collection, where each item is an ISlide. All add, delete, copy, and reorder operations ultimately act on this collection.
Presentation implements IDisposable. When reading from or writing to files, declare it with using to ensure handles are disposed promptly.
Adding Slides
When you instantiate a Presentation, the library automatically adds a blank slide. If you want to build from scratch, first remove this default slide:
using var ppt = new Presentation(); ppt.Slides.RemoveAt(0); After that, there are two ways to add slides:
ppt.Slides.Append(); // Append a blank slide at the end ppt.Slides.Insert(1); // Insert a blank slide at index 1 (indexes start at 0) When called without parameters, Append() adds a blank slide at the end. Insert(index) likewise inserts a blank slide. Neither copies any existing content.
Deleting Slides
Delete by index or by object reference:
ppt.Slides.RemoveAt(0); // Delete by index ISlide target = ppt.Slides[2]; ppt.Slides.Remove(target); // Delete by object reference Before deleting, verify that ppt.Slides.Count > index to avoid an out-of-range exception. If you need to delete multiple slides, iterate in reverse order:
for (int i = ppt.Slides.Count - 1; i >= 0; i--) { if (ShouldDelete(ppt.Slides[i])) ppt.Slides.RemoveAt(i); } Calling RemoveAt during forward iteration shifts the indexes of subsequent elements, which can cause missed deletions or out-of-range errors.
Copying Slides
To copy a slide, pass an existing ISlide object to Append or Insert. The layout, images, and formatting are preserved.
Copying within the same document:
ISlide source = ppt.Slides[0]; ppt.Slides.Append(source); // Copy to the end ppt.Slides.Insert(2, source); // Copy and insert at index 2 Cross-document copying requires no additional conversion. Simply pass the source document's ISlide into the target document's collection:
using var sourcePpt = new Presentation(); sourcePpt.LoadFromFile("source.pptx"); using var targetPpt = new Presentation(); targetPpt.LoadFromFile("target.pptx"); ISlide toCopy = sourcePpt.Slides[0]; targetPpt.Slides.Insert(0, toCopy); From a code perspective, the only difference between "copying" and "inserting a blank slide" is whether the second parameter of Insert is an ISlide object.
Hiding Slides
ISlide exposes a Boolean property named Hidden, which controls whether the slide is skipped during a slide show:
ppt.Slides[1].Hidden = true; // Hide the second slide ppt.Slides[1].Hidden = false; // Unhide it This behavior matches PowerPoint semantics: the slide is skipped during a slide show but remains visible and editable in editing view. Hiding a slide does not change the structure of the Slides collection, so you do not need to iterate in reverse order when setting it for multiple slides.
These APIs cover the most commonly used slide-level management operations: adding, deleting, copying, and hiding slides. They are well suited to automation scenarios such as batch-organizing PPT pages, dynamically paginating templates, and controlling which slides appear during a slide show.

