If the presentation is empty or has just one slide the code below (and that's expected) returns 1 ID, but the presentation has 10+ masters. How can I get the full list of existing masters in an any presentation?
static string[,] GetSlideMasterIds(string templatePath)
{
List<string[]> slideMasterIdList = new List<string[]>();
using (PresentationDocument presentationDocument = PresentationDocument.Open(templatePath, false))
{
// Get the main presentation part
PresentationPart presentationPart = presentationDocument.PresentationPart;
// Get the slide id list
SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;
// Iterate through slide ids
foreach (SlideId slideId in slideIdList.Elements<SlideId>())
{
string slideIdValue = slideId.Id.ToString();
string relationshipId = slideId.RelationshipId;
slideMasterIdList.Add(new string[] { slideIdValue, relationshipId });
}
}
// Convert the list to a two-dimensional array
string[,] slideMasterIds = new string[slideMasterIdList.Count, 2];
for (int i = 0; i < slideMasterIdList.Count; i++)
{
slideMasterIds[i, 0] = slideMasterIdList[i][0]; // Slide ID
slideMasterIds[i, 1] = slideMasterIdList[i][1]; // Relationship ID
}
return slideMasterIds;
}
I've also tryed to get the IDs by using the relationship between Slide Layouts and Master Slides, but there was a mess. Any suggestions?