Clone/Duplicate current slide using open xml memory stream RRS feed

  • Question

  • here i am duplicate slide and write the code on duplicate slide using memory stream,after performing operation and sending to save and sending to blob without using local path..

    issue was clone slide layout(template) not getting and ppt get repairing which saveas in local working fine.

    i tried 

    public static SlidePart CloneSlidePart(PresentationPart presentationPart, SlidePart slideTemplate)

                Slide currentSlide = (Slide)slideTemplate.Slide.CloneNode(true);

                // Create a new slide part in the presentation 
                var newSlidePart = presentationPart.AddNewPart<SlidePart>();
                newSlidePart.AddPart(slideTemplate.SlideLayoutPart, slideTemplate.GetIdOfPart(slideTemplate.SlideLayoutPart));

                // Copy the image parts
                foreach (ImagePart ipart in slideTemplate.ImageParts)
                    ImagePart newipart = newSlidePart.AddImagePart(ipart.ContentType, slideTemplate.GetIdOfPart(ipart));

                // Get the list of slide ids 
                SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;

                // Figure out where to add the next slide (find max slide) 
                uint maxSlideId = 1;
                SlideId prevSlideId = null;
                foreach (SlideId slideId in slideIdList.ChildElements.OfType<SlideId>())
                    var part = presentationPart.GetPartById(slideId.RelationshipId);

                    if (part == slideTemplate)
                        prevSlideId = slideId;

                    if (slideId.Id > maxSlideId)
                        maxSlideId = slideId.Id;

                SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);
                newSlideId.Id = maxSlideId;
                newSlideId.RelationshipId = presentationPart.GetIdOfPart(newSlidePart);
                return newSlidePart;

    Wednesday, March 6, 2019 1:13 PM