dotnet / dotnet/Open-XML-SDK

`PresentationDocument.Save()` doesn't apply changes

Open
#1,147 7 comments 0 reactions 1 assignee Claimed by @twsouthwick View on GitHub
Dominant language
C#
Stars
4.6k
Forks
605
PR merge metrics
No merged PRs in 30d

Description

**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](https://github.com/OfficeDev/Open-XML-SDK/files/8662785/base.pptx)

```csharp
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().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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.