public static void SetSlideID(PresentationPart presentationPart, SlidePart slidePart1) { // Insert the new slide into the slide list after the previous slide. SlideIdList slideIdList = presentationPart.Presentation.SlideIdList; // Find the highest slide ID in the current list. uint maxSlideId = 1; SlideId prevSlideId = null; foreach (SlideId slideId in slideIdList.ChildElements) { if (slideId.Id > maxSlideId) { maxSlideId = slideId.Id; prevSlideId = slideId; } } maxSlideId++; SlideId newSlideId = slideIdList.AppendChild(new SlideId()); newSlideId.Id = maxSlideId; newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart1); }
public void Add() { //need to assign an id to the new slide and add it to the slideIdList //first figure out the largest existing id SlideIdList slideIdList = _doc.PresentationPart.Presentation.SlideIdList; uint[] maxSlideId = { 1 }; foreach ( SlideId slideId in slideIdList.ChildElements.Cast <SlideId>().Where(slideId => slideId.Id > maxSlideId[0])) { maxSlideId[0] = slideId.Id; } //assign an id and add the new slide at the end of the list var newSlideId = new SlideId { Id = ++maxSlideId[0], RelationshipId = _doc.PresentationPart.GetIdOfPart(NewSlidePart) }; slideIdList.AppendChild(newSlideId); }