How to Remove Slides from a Presentation

Sometimes, we may need to delete specific slide in a PowerPoint presentation due to any reason. This section will illustrate that how we can accomplish that task using Spire.Presentation for .NET.

As a matter of fact, it is quite easy and convenient to remove slides by only one line of core code if you have Spire.Presentation.Dll installed as a reference in your .NET project assemblies. Here is the method:

Step 1: Create an instance of presentation class and load PPT documents

Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");

Step 2: Remove the second slide from the presentation by using its index position

presentation.Slides.RemoveAt(1);

Step 3: Save and review

presentation.SaveToFile("result.pptx",FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");

Original layout:

Remove Slides from a Presentation

Result:

Remove Slides from a Presentation

Full C# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Presentation;

namespace RemoveSlide
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("sample.pptx");

            //remove the second slide
            presentation.Slides.RemoveAt(1);

             presentation.SaveToFile("result.pptx",FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");
        }
    }
}