News Category

Change the Slide Order within a Presentation in C#, VB.NET

2014-11-20 08:04:44 Written by  support iceblue
Rate this item
(0 votes)

During the creation of a PowerPoint slide, a new slide automatically places at the end of the presentation. At some point, you may want to change the order of your slides. One way to arrange slides is via 'drag and drop' in the Normal View of MS PowerPoint. In this section, I'll introduce how to reorder PowerPoint slides programmatically using Spire.Presentation in C#, VB.NET.

To begin with, create or open a .NET class application in Visual Studio 2005 or above versions, add Spire.Presentation.dll to your .NET project assemblies. Then, you are able to change the slide order using the sample code we have offered below.

Code Snippet

Step 1: Create a new instance of Spire.Presentation and load the test file.

Presentation presentation = new Presentation("Test.pptx", FileFormat.Pptx2010);

Step 2: Get the first slide by its index and set its SlideNumber=2. To do so, 1st slide and 2nd slide will switch position with a new order being saved.

ISlide slide = presentation.Slides[0];
       slide.SlideNumber = 2;

Step 3: Get the second slide in the new order and set its SlideNumber=3. This way, 2nd slide will be transformed to 3rd place.

slide = presentation.Slides[1];
       slide.SlideNumber = 3;

Step 4: Save the file.

presentation.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Screenshot of Effect:

Change the Slide Order within a Presentation in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
namespace ChangeSlideOrder
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation("Test.pptx", FileFormat.Pptx2010);

            ISlide slide = presentation.Slides[0];
            slide.SlideNumber = 2;

            slide = presentation.Slides[1];
            slide.SlideNumber = 3;

            presentation.SaveToFile("Result.pptx", FileFormat.Pptx2010);


        }
    }
}
[VB.NET]
Imports Spire.Presentation
Namespace ChangeSlideOrder
	Class Program
		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation("Test.pptx", FileFormat.Pptx2010)

			Dim slide As ISlide = presentation.Slides(0)
			slide.SlideNumber = 2

			slide = presentation.Slides(1)
			slide.SlideNumber = 3

			presentation.SaveToFile("Result.pptx", FileFormat.Pptx2010)


		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title: Change the Slide Order
Last modified on Friday, 24 September 2021 09:12