'C# not reading the whole PPTX file after editing it
I'm trying to read a PPTX file in C# and using it as a template for filling it up with data. When I read the original file it reads correctly the whole 52 slides file, but when I add (via PowerPoint) a slide to it, it seems like it breaks and when I try to read it again programmatically it only reads 40 out of the 53 slides. How can I avoid that? I checked the XML of the presentation and actually there are all 53 XML files each one related to a slide. I'm reading the file via DocumentFormat.OpenXML API and iterating through the whole slides set but it stops at 40 slides.
Here is the sample code I use to read the slides:
slides = new Dictionary<int, Slide>();
_presentationDocument = DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(presentationStream, true);
_presentationPart = _presentationDocument.PresentationPart;
if (_presentationPart != null && _presentationPart.Presentation != null)
{
_presentation = _presentationPart.Presentation;
if (_presentation.SlideIdList != null)
{
int pageNumber = 1;
foreach (var slideId in _presentation.SlideIdList.Elements<DocumentFormat.OpenXml.Presentation.SlideId>())
{
DocumentFormat.OpenXml.Packaging.SlidePart slidePart = _presentationPart.GetPartById(slideId.RelationshipId) as DocumentFormat.OpenXml.Packaging.SlidePart;
slides.Add(pageNumber, new Slide(_presentationPart, slidePart, pageNumber));
pageNumber++;
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
