Example #1
0
        /// <summary>
        /// Sets a core property value.
        /// Private method, for internal use only!
        /// </summary>
        /// <param name="nameSpace">The property's namespace</param>
        /// <param name="propertyName">The name of the property</param>
        /// <param name="propValue">The value of the property</param>
        private void SetCorePropertyValue(string nameSpace, string propertyName, string propValue)
        {
            string  searchString = string.Format("//cp:coreProperties/{0}:{1}", nameSpace, propertyName);
            XmlNode node         = CorePropertiesXml.SelectSingleNode(searchString, _nsManager);

            if (node == null)
            {
                // the property does not exist, so create the XML node
                string schema = schemaCore;
                switch (nameSpace)
                {
                case "cp": schema = schemaCore; break;

                case "dc": schema = schemaDc;   break;

                case "dcterms": schema = schemaDcTerms; break;

                case "dcmitype": schema = schemaDcmiType;       break;

                case "xsi": schema = schemaXsi; break;
                }
                node = (XmlNode)CorePropertiesXml.CreateElement(nameSpace, propertyName, schema);
                CorePropertiesXml.DocumentElement.AppendChild(node);
            }
            node.InnerText = propValue;
        }
Example #2
0
        /// <summary>
        /// Sets a core property value.
        /// Private method, for internal use only!
        /// </summary>
        /// <param name="nameSpace">The property's namespace</param>
        /// <param name="propertyName">The name of the property</param>
        /// <param name="propValue">The value of the property</param>
        private void SetCorePropertyValue(string nameSpace, string propertyName, string propValue)
        {
            string searchString = string.Format("//cp:coreProperties/{0}:{1}", nameSpace, propertyName);
            var    node         = CorePropertiesXml.XPathSelectElement(searchString, _nsManager);

            if (node == null)
            {
                // the property does not exist, so create the XML node
                string schema = schemaCore;
                switch (nameSpace)
                {
                case "cp": schema = schemaCore; break;

                case "dc": schema = schemaDc;   break;

                case "dcterms": schema = schemaDcTerms; break;

                case "dcmitype": schema = schemaDcmiType;       break;

                case "xsi": schema = schemaXsi; break;
                }
                node = new XElement(propertyName)
                       .AddSchemaAttribute(schema, nameSpace);
                CorePropertiesXml.Document.Add(node);
            }
            node.Value = propValue;
        }
Example #3
0
        /// <summary>
        /// Provides access to all the office document properties.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="ns"></param>
        internal OfficeProperties(ExcelPackage package, XmlNamespaceManager ns) :
            base(ns)
        {
            _package = package;

            _coreHelper     = XmlHelperFactory.Create(ns, CorePropertiesXml.SelectSingleNode("cp:coreProperties", NameSpaceManager));
            _extendedHelper = XmlHelperFactory.Create(ns, ExtendedPropertiesXml);
            _customHelper   = XmlHelperFactory.Create(ns, CustomPropertiesXml);
        }
Example #4
0
        /// <summary>
        /// Provides access to all the office document properties.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="ns"></param>
        internal OfficeProperties(ExcelPackage package, XmlNamespaceManager ns) :
            base(ns)
        {
            _package = package;

            _coreHelper       = XmlHelperFactory.Create(ns, CorePropertiesXml.SelectSingleNode("cp:coreProperties", NameSpaceManager));
            _extendedHelper   = XmlHelperFactory.Create(ns, ExtendedPropertiesXml);
            _customHelper     = XmlHelperFactory.Create(ns, CustomPropertiesXml);
            _customProperties = new Dictionary <string, XmlElement>(StringComparer.CurrentCultureIgnoreCase);
            LoadCustomProperties();
        }
Example #5
0
        /// <summary>
        /// Gets the value of a core property
        /// Private method, for internal use only!
        /// </summary>
        /// <param name="nameSpace">The namespace of the property</param>
        /// <param name="propertyName">The property name</param>
        /// <returns>The current value of the property</returns>
        private string GetCorePropertyValue(string nameSpace, string propertyName)
        {
            string  retValue     = null;
            string  searchString = string.Format("//cp:coreProperties/{0}:{1}", nameSpace, propertyName);
            XmlNode node         = CorePropertiesXml.SelectSingleNode(searchString, _nsManager);

            if (node != null)
            {
                retValue = node.InnerText;
            }
            return(retValue);
        }
Example #6
0
        /// <summary>
        /// Gets the value of a core property
        /// Private method, for internal use only!
        /// </summary>
        /// <param name="nameSpace">The namespace of the property</param>
        /// <param name="propertyName">The property name</param>
        /// <returns>The current value of the property</returns>
        private string GetCorePropertyValue(string nameSpace, string propertyName)
        {
            string retValue     = null;
            string searchString = string.Format("//cp:coreProperties/{0}:{1}", nameSpace, propertyName);
            var    node         = CorePropertiesXml.XPathSelectElement(searchString, _nsManager);

            if (node != null)
            {
                retValue = node.Value;
            }
            return(retValue);
        }