public void P002_Pptx_DeleteAdd_CoreExtendedProperties() { var docName = "Presentation.pptx"; var ba = File.ReadAllBytes(s_TestFileLocation + docName); using (MemoryStream ms = new MemoryStream()) { ms.Write(ba, 0, ba.Length); using (PresentationDocument doc = PresentationDocument.Open(ms, true)) { var corePart = doc.CoreFilePropertiesPart; var appPart = doc.ExtendedFilePropertiesPart; var custFilePropsPart = doc.CustomFilePropertiesPart; var thumbNailPart = doc.ThumbnailPart; doc.DeletePart(corePart); doc.DeletePart(appPart); if (thumbNailPart != null) { doc.DeletePart(thumbNailPart); } doc.AddCoreFilePropertiesPart(); doc.AddExtendedFilePropertiesPart(); doc.AddCustomFilePropertiesPart(); doc.AddDigitalSignatureOriginPart(); doc.AddExtendedPart("relType", "contentType/xml", ".xml"); var tnPart = doc.AddThumbnailPart(ThumbnailPartType.Jpeg); doc.DeletePart(tnPart); tnPart = doc.AddThumbnailPart("image/jpg"); OpenXmlValidator v = new OpenXmlValidator(FileFormatVersions.Office2013); var errs = v.Validate(doc); Assert.Equal(94, errs.Count()); } } }
private static PresentationDocument BuildPresentationScaffold(PresentationDocument presentationDocument) { presentationDocument.DeletePartsRecursivelyOfType <PresentationPart>(); presentationDocument.DeletePartsRecursivelyOfType <CoreFilePropertiesPart>(); presentationDocument.DeletePartsRecursivelyOfType <ExtendedFilePropertiesPart>(); presentationDocument.ChangeIdOfPart(presentationDocument.AddPresentationPart(), "rId1"); PresentationBuilder.MakeValidPresentationPart(presentationDocument.PresentationPart); presentationDocument.ChangeIdOfPart(presentationDocument.AddCoreFilePropertiesPart(), "rId2"); PresentationBuilder.MakeValidCoreFilePropertiesPart(presentationDocument.CoreFilePropertiesPart); presentationDocument.ChangeIdOfPart(presentationDocument.AddExtendedFilePropertiesPart(), "rId3"); PresentationBuilder.MakeValidExtendedFilePropertiesPart(presentationDocument.ExtendedFilePropertiesPart); return(presentationDocument); }