Saving and autosaving PowerPoint OpenXML PresentationDocuments

2.7k views Asked by At

I'm looking for some advice about saving OpenXML documents, specifically a PresentationDocument.

In my scenario I open a PowerPoint .pptx presentation directly from disk, that acts as a template. I then add (copy) slides from various other PowerPoint presentations. For each separate source presentation I also add its MasterSlideParts and SlideLayoutParts.

Question 1: When the presentation needs saving, is there a single command I can issue that will save all changes to the PresentationDocument? Or do I have to manually save each item that is new or been been changed, eg:

        presentationDocument.PresentationPart.Presentation.Save();

        foreach (var slideMasterPart in presentationDocument.PresentationPart.SlideMasterParts)
        {
            slideMasterPart.SlideMaster.Save();
        }

Question 2: When opening a PresentationDocument, there is an option for "autosave" which seems to default to "true". Can anyone explain exactly what autosave does?

Something I read suggests that this saves everything in the PresentationDocument when the PresentationDocument is disposed of. Is this correct?

If so, I will need to set autosave=false, since I will need to control saving myself, in order to be able to test the presentation-building logic.

Thanks in advance for any answers.

Steve

1

There are 1 answers

1
amurra On BEST ANSWER

Question 1: If you are using streams to open your file and do the modifications that way you will not need to explicitly call either one of those save calls. You will just need to call the Dispose() method on the presentationDocument variable. The documentation states for dispose

Flushes and saves the content, closes the document, and releases all resources.

This will save you from having to call save on the presentation or by looping through each individual slide.

Question 2: The documentation for autosave states the following:

Gets the flag indicating whether the parts should be saved on disposing.

This would lead me to believe that if you want all the parts to be saved when calling the Dispose() method you would want this value to be set to true. Otherwise, your changes might not be saved.