Merging presentations with moving slides to sections

Hi,

I want to merge some pptx files into one.

Creating sections in base.pptx works.

Cloning slides works, slides go to section[0].

When I want to move recently copied slide to last created section I get an error:

System.IndexOutOfRangeException: Index was out of range,value should be greater than slide count


//base pptx has 'START' section and one slide inside it
IPresentation outputPptx = Presentation.Open(@"Z:\base.pptx");
IPresentation sourcePresentation;

//PptFilesSelectedCollection is a collection of selected files in sfDataGrid not mentioned here
foreach (object element in PptFilesSelectedCollection)
{
//PptFileModel.FullName is a path to the file, .SectionName is a section name PptFileModel file = element as PptFileModel; sourcePresentation = Presentation.Open(file.FullName); ISection section = outputPptx.Sections.Add(); section.Name = file.SectionName; foreach (ISlide sourceSlide in sourcePresentation.Slides) { ISlide clonedSlide = sourceSlide.Clone(); outputPptx.Slides.Add(clonedSlide, PasteOptions.SourceFormatting, outputPptx); ISlide slide = outputPptx.Sections[0].Slides[1]; // the error shows here //Moves the slide to last added section slide.MoveToSection(outputPptx.Sections.Count - 1); } sourcePresentation.Close();
}
outputPptx.Save(@"Z:\output.PPTX");
outputPptx.Close();

What do I do wrong?


3 Replies

MR Manikandan Ravichandran Syncfusion Team February 9, 2022 03:47 PM UTC

Hi Jakub,

From the given details, we have found that your requirement is to move the cloned slides from one document to section of another Presentation document. For this, you can use below two approaches.

1. Directly add the cloned slide to Section.
You can add cloned slide directly in the section of another document using the below code example. 
foreach (ISlide sourceSlide in sourcePresentation.Slides)
{
       ISlide clonedSlide = sourceSlide.Clone();
       outputPptx.Sections[0].Slides.Add(clonedSlide, PasteOptions.SourceFormatting, outputPptx);

} 

2. Add cloned slide to slides collection and move to section:
You can add the cloned slide in the slide collection of the Presentation document and get that added slide and then move to created section using MoveToSection API. 
foreach (ISlide sourceSlide in sourcePresentation.Slides)
{
      ISlide clonedSlide = sourceSlide.Clone();
      outputPptx.Slides.Add(clonedSlide, PasteOptions.SourceFormatting, outputPptx);
      ISlide slide = outputPptx.Slides[0];
     
//Moves the slide to last added section
      slide.MoveToSection(0);
}
 

But in this approach, we are facing IndexOutOfRangeException at our end and currently we are validating this issue. We will share the details for this on 11th February 2022.

Regards,
Manikandan Ravichandran 



MR Manikandan Ravichandran Syncfusion Team February 11, 2022 02:56 PM UTC

Hi Jakub,

We have confirmed the reported issue with “IndexOutOfRangeException thrown when moving cloned slides to section in PowerPoint presentation” as a defect in our end. We will include the fix for this issue in our upcoming weekly NuGet release on 01st March 2022

Please use the below feedback link to track the status of the reported bug.
https://www.syncfusion.com/feedback/32636/indexoutofrangeexception-thrown-when-moving-cloned-slides-to-section-in-powerpoint

Regards,
Manikandan Ravichandran
 



MR Manikandan Ravichandran Syncfusion Team March 1, 2022 02:37 PM UTC

Hi Jakub,

As promised earlier, we have included the fix for the reported issue with “IndexOutOfRangeException thrown when moving cloned slides to section in PowerPoint presentation" in our latest weekly NuGet release (v19.4.0.54).

Please use the below link to download our latest weekly NuGet:
https://www.nuget.org/packages/Syncfusion.Presentation.Wpf/19.4.0.54

The status of this bug task can be tracked through the below link:
https://www.syncfusion.com/feedback/32636/indexoutofrangeexception-thrown-when-moving-cloned-slides-to-section-in-powerpoint

Note: We will include this fix in our 2022 Volume 1 Main release which will be available in March 2022.

Regards,
Manikandan Ravichandran 


Loader.
Up arrow icon