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
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 thepresentationDocument
variable. The documentation states for disposeThis 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: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.