Media References are removed
Hi I encountered the following issue while using the OpenXML SDK:
Description I opened the attached file with the OpenXML SDK and saved it using a different name. If I try to open the saved file Power Point reports that the file is broken and that it can try to repair it. After repairing the document does not contain the video which was originally in the presentation.
Information
- .NET Target: .NET Core
- DocumentFormat.OpenXml Version: 2.13.0-beta2
Repro
Use the following code with the attached file and try to open the saved pptx file.
var ppt = PresentationDocument.Open("source.pptx", false);
ppt.SaveAs("saved.pptx");
Observed
The saved file is broken and has to be repaired. The repaired file does not contain the video anymore. Somehow the OpenXML SDK removes all the media references contained in the pptx file.
Expected
A valid pptx file that is identical to the original document.
I would also be willing to help working on a fix if someone could provide me a starting point why/where the references are removed.
Thanks and kind regards, Lars
@lklein53 Can you try the latest beta? 2.7.1 is quite old at this point.
@twsouthwick thanks for your quick reply. Sorry messed up the bug report. I already tried using version v2.13.0-beta2
Thanks! So to be clear, it removes them in both? Trying to understand if it is a regression from an earlier version that may have been working as expected.
Yes, both versions produce a broken pptx without the video in it.
Thanks! At least it's not a regression. Not sure off the top of my head why it's being removed, but we'd gladly accept a PR!
Hi, I had some time to look into this today. In line 1731 of the OpenXmlPartContainer is the following code:
var newDataPartReference = DataPartReferenceRelationship.Create(this, newDataPart, dataPartReferenceRelationship.RelationshipType, dataPartReferenceRelationship.Id);
ReferenceRelationshipList.AddLast(newDataPartReference);
I think this has to be replaced by
var newDataPartReference = DataPartReferenceRelationship.Create(child, newDataPart, dataPartReferenceRelationship.RelationshipType, dataPartReferenceRelationship.Id);
child.AddDataPartReferenceRelationship(newDataPartReference);
At least my example works with this change. If you agree I will create a PR for it. Including a test case
Awesome! Go ahead and make a PR and we can explore it further
https://github.com/OfficeDev/Open-XML-SDK/pull/934 contains the change and a simple regression test
@tomjebo Can you take a look to verify this change makes sense?
@twsouthwick can this issue be closed? Somehow my changes have been merged in June last year already (https://github.com/OfficeDev/Open-XML-SDK/pull/934)