-
Notifications
You must be signed in to change notification settings - Fork 3
Count the number of Slides
ZeeshanShafqat edited this page Jan 28, 2014
·
2 revisions
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Number of slides = {0}",
CountSlides("Count the number of slides.pptx"));
Console.ReadKey();
}
// Get the presentation object and pass it to the next CountSlides method.
public static int CountSlides(string presentationFile)
{
// Open the presentation as read-only.
using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, false))
{
// Pass the presentation to the next CountSlide method
// and return the slide count.
return CountSlides(presentationDocument);
}
}
// Count the slides in the presentation.
public static int CountSlides(PresentationDocument presentationDocument)
{
// Check for a null document object.
if (presentationDocument == null)
{
throw new ArgumentNullException("presentationDocument");
}
int slidesCount = 0;
// Get the presentation part of document.
PresentationPart presentationPart = presentationDocument.PresentationPart;
// Get the slide count from the SlideParts.
if (presentationPart != null)
{
slidesCount = presentationPart.SlideParts.Count();
}
// Return the slide count to the previous method.
return slidesCount;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Number of slides = {0}",
CountSlides("Count the number of slides.pptx"));
Console.ReadKey();
}
public static int CountSlides(string presentationFile)
{
//Instantiate a PresentationEx object that represents a PPTX file
using (PresentationEx pres = new PresentationEx(presentationFile))
{
return pres.Slides.Count;
}
}
}
Download