RemoveAt(int pos) doesn't work normally

Hi,

I’m trying to delete a specific Slide in my Document, and it don’t supress the good one.

Let me provide some information because it’s a little bit strange:

If I made by myself (using Microsoft PowerPoint) a PowerPoint Document with 24 Slides, and I choose to delete the first slide I use this command


Presentation pres = …
pres.Slides.RemoveAt(0);
And it’s Work
Now I decide to delete the last Slide, so I use


Presentation pres = …
pres.RemoveAt(pres.Slides.LastSlidePosition-1);
And It’s well work too.
But If I provide a different document, one from a ASPOSE generation, It doesn’t work, and it delete for the first case the 21th slide and for the second case the 4th slide. Very Strange

I provide you my PowerPoint Document generated by my Visual Solution based on ASPOSE.PowerPoint v 2.0.5.1

After testing differents position to delete I obtain this result (I based my test on my PowerPoint Generated with 24 Slides):


[Position specified] [Slide Deleted]
[ 0 ] [ 21 ]
[ 1 ] [ 22 ]
[ 23 ] [ 4 ]
[ 22 ] [ 3 ]
[ 20 ] [ 1 ]
[ 19 ] [ 8 ]
Here the code I use to test it


private void button1_Click(object sender, System.EventArgs e)

{

Presentation pres = new Presentation(“Test.ppt”);

MessageBox.Show("Nb Slides : " + pres.Slides.Count.ToString());

pres.Slides.RemoveAt(Int32.Parse(textBox1.Text));

pres.Write(“Test Result.ppt”);

MessageBox.Show("Nb Slides : " + pres.Slides.Count.ToString());

}



Thanks for Help because I really need to delete specific Slide.



Hi,

Slide position in presentation is not equal to position of slide in Slides collection.
To delete specific slide you should write something like that:

pres.Slides.Remove(pres.GetSlideByPosition(1));

Ok, It’s work now…
Thanks fo your quickly answer.

I understand that in the ASPOSE.PowerPoint Slides are stock in a Collection, so if I want to copy 3 Differents slides 2 two times I have to do like That:


int nbSlides = 3;
for (int x=1; x <= nbSlides; x++)
{
pres.CloneSlide(pres.GetSlideByPosition(x), pres.Slides.Count);
}


But It does’nt work.
I’m sure it’s something stupid like before, bt I don’t really understand the way to do.

Thanks for your help

What doesn’t work in your code?

I’d suggest to write:
pres.CloneSlide(pres.GetSlideByPosition(x), pres.Slides.LastSlidePosition + 1);

But in whole your code is correct and must work.

True, it was a secondary probleme…
Sorry, and thanks you very much …