/* /// <summary> * /// Adds the documentProtection element to a document * /// </summary> * public void AddDocumentProtection() * { * //Finds the custom properties part * XDocument customPropertiesDocument = null; * XElement documentProtectionElement = null; * * if (parentDocument.Document.WorkbookPart.CustomPropertyPart == null) * { * //If settings part does not exist creates a new one * customPropertiesDocument = CreateCustomPropertiesPart(); * } * else * { * //If the custom properties part does exist, look if the document protection already exists * customPropertiesDocument = parentDocument.GetXDocument(parentDocument.Document.WorkbookPart.CustomPropertyPart); * XName propertyTagName = customPropertiesns + "property"; * XName propertyAttributeName = customPropertiesns + "name"; * XName propertyName = "_MarkAsFinal"; * documentProtectionElement = customPropertiesDocument.Descendants().Where( * tag => * (tag.Name == propertyTagName) && (tag.Attribute(propertyAttributeName).Value == propertyName) * ).First(); * } * * // create a document protection element if it doesn't exist * if (documentProtectionElement == null) * { * customPropertiesDocument.Root.Add( * new XElement(customPropertiesns + "property", * new XAttribute("fmtid", "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"), * new XAttribute("pid", "456"), * new XAttribute("name", "_MarkAsFinal"), * new XElement(vTypesns + "bool", "true"))); * } * }*/ internal void RemoveAll() { IEnumerable <OpenXmlSDK.CustomFilePropertiesPart> customPropertiesParts = parentDocument.Document.GetPartsOfType <OpenXmlSDK.CustomFilePropertiesPart>(); if (customPropertiesParts != null && customPropertiesParts.Count() > 0) { parentDocument.RemovePart(customPropertiesParts.First()); } }
internal void RemoveAll() { IEnumerable <CoreFilePropertiesPart> corePropertiesParts = parentDocument.Document.GetPartsOfType <CoreFilePropertiesPart>(); if (corePropertiesParts != null && corePropertiesParts.Count() > 0) { parentDocument.RemovePart(corePropertiesParts.First()); } }