how to copy Power Point slides into a presentation using OOXML and c# RRS feed

  • Question

  • Within a loop  I create Power Point slides using OOXML and C#. After I save them (one at a time) , I copy that slide into a Final_presentation.pptx file using the following code:

    public void CopySlideIntoPresentation(string slide_to_copy, string presentation_to_save)
            //generate a random number
            Random random = new Random();
            int i = random.Next(10, 100000);

            //Copy slide into final_presentation
            using (PresentationDocument newDocument = PresentationDocument.Open(presentation_to_save, true))
                PresentationDocument templateDocument = PresentationDocument.Open(slide_to_copy, false);

                uint uniqueId = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideMasterIdList);
                uint maxId = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideIdList);

                //SlidePart oldPart = GetSlidePartByTagName(templateDocument, "rId1");
                SlidePart oldPart = templateDocument.PresentationPart.SlideParts.First();

                SlidePart newPart = newDocument.PresentationPart.AddPart<SlidePart>(oldPart, "sourceId" + i);

                SlideMasterPart newMasterPart = newDocument.PresentationPart.AddPart(newPart.SlideLayoutPart.SlideMasterPart);

                SlideIdList idList = newDocument.PresentationPart.Presentation.SlideIdList;

                // create new slide ID


                SlideId newId = new SlideId();

                newId.Id = maxId;

                newId.RelationshipId = "sourceId" + i;


                // Create new master slide ID


                SlideMasterId newMasterId = new SlideMasterId();

                newMasterId.Id = uniqueId;

                newMasterId.RelationshipId = newDocument.PresentationPart.GetIdOfPart(newMasterPart);


                // change slide layout ID



                //return true;



    Even though all the slides get copied into final_presentation.pptx file, I get the following error when open it:

    "Powerpoint found unreadable content in final_presntation.pptx. Do you want to recover the contents of this presentation? If you trust the source of this presentation click Yes"

    I click "yes" and then I get:

    "The file cannot be open by using Microsoft Office Powerpoint. Do you want to search the Microsoft Office Online website for a converter that can open the file? "

    I click "No" and I can see the new slide inserted into this final_presentation file.

    Can someone help me to solve this error?


    • Moved by Lie You Thursday, October 20, 2011 3:04 AM Move it for good discussion (From:Visual C# Language)
    • Moved by Cindy Meister MVPModerator Thursday, October 20, 2011 6:49 AM Open XML related (From:General Office Development)
    Tuesday, October 18, 2011 11:01 AM

All replies

  • I post it to this category for good discussion.

    Thanks for your understanding and support.

    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, October 20, 2011 3:06 AM
  • Hi Manka

    The better place for this question than the General Office Development forum is the Open XML SDK forum, where OOXML is the topic. So I'm moving your question there.

    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by kajimaru Wednesday, May 18, 2016 12:50 AM
    Thursday, October 20, 2011 6:48 AM