Skip to content

PresentationDocument.Save() doesn't apply changes #1147

@ashahabov

Description

@ashahabov

Description

PresentationDocument.Save() doesn't apply changes that are deleting presentation sections. It works if I call doc.Close() (check Repro), but I don't wanna close presentation before mStream.ToArray().

Looks like PresentationDocument.Save() doesn't flush changes to mStream stream.

Information

  • .NET Target: .NET 6
  • DocumentFormat.OpenXml Version: 2.16.0

Repro

base.pptx

using DocumentFormat.OpenXml.Office2010.PowerPoint;
using DocumentFormat.OpenXml.Packaging;

using var fStream = File.OpenRead(@"c:\temp\base.pptx");
var mStream = new MemoryStream();
fStream.CopyTo(mStream);
fStream.Close();

using var doc = PresentationDocument.Open(mStream, true);
var sectionList = doc.PresentationPart!.Presentation.PresentationExtensionList?.Descendants<SectionList>().First();

sectionList.Remove();
doc.Save();
// doc.Close() // it works

File.WriteAllBytes(@"c:\temp\edited.pptx", mStream.ToArray());

// ...

Observed

edited.pptx still has section.

Expected

edited.pptx doesn't have sections.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions