Example #1
0
        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());
                }
            }
        }