当前位置: 首页>>代码示例>>C#>>正文


C# PackagePartName类代码示例

本文整理汇总了C#中PackagePartName的典型用法代码示例。如果您正苦于以下问题:C# PackagePartName类的具体用法?C# PackagePartName怎么用?C# PackagePartName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PackagePartName类属于命名空间,在下文中一共展示了PackagePartName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PackagePart

        /**
         * Constructor.
         * 
         * @param pack
         *            Parent package.
         * @param partName
         *            The part name, relative to the parent Package root.
         * @param contentType
         *            The content type.
         * @param loadRelationships
         *            Specify if the relationships will be loaded
         * @throws InvalidFormatException
         *             If the specified URI is not valid.
         */
        protected PackagePart(OPCPackage pack, PackagePartName partName,
                ContentType contentType, bool loadRelationships)
        {
            this.partName = partName;
            this.contentType = contentType;
            this.container = (ZipPackage)pack; // TODO - enforcing ZipPackage here - perhaps should change constructor signature

            // Check if this part is a relationship part
            isRelationshipPart = this.partName.IsRelationshipPartURI();

            // Load relationships if any
            if (loadRelationships)
                LoadRelationships();
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:28,代码来源:PackagePart.cs

示例2: Main

        static void Main(string[] args)
        {
            OPCPackage p = OPCPackage.Open("test.zip", PackageAccess.READ_WRITE);

            PackagePartName pn3 = new PackagePartName(new Uri("/c.xml", UriKind.Relative), true);
            if (!p.ContainPart(pn3))
                p.CreatePart(pn3, MediaTypeNames.Text.Xml);

            //save file 
            p.Save("test1.zip");

            //don't forget to close it
            p.Close();

        }
开发者ID:89sos98,项目名称:npoi,代码行数:15,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            //create ooxml file in memory
            Package p = Package.Create();

            //create package parts
            PackagePartName pn1=new PackagePartName(new Uri("/a/abcd/e",UriKind.Relative),true);
            if (!p.ContainPart(pn1))
                p.CreatePart(pn1, MediaTypeNames.Text.Plain);

            PackagePartName pn2 = new PackagePartName(new Uri("/b/test.xml", UriKind.Relative), true);
            if (!p.ContainPart(pn2))
                p.CreatePart(pn2, MediaTypeNames.Text.Xml);

            //save file 
            p.Save("test.zip");

            //don't forget to close it
            p.Close();
        }
开发者ID:hanwangkun,项目名称:npoi,代码行数:20,代码来源:Program.cs

示例4: RemovePartImpl

        /**
         * Delete a part from the package
         *
         * @throws ArgumentException
         *             Throws if the part URI is nulll or invalid.
         */

        protected override void RemovePartImpl(PackagePartName partName)
        {
            if (partName == null)
                throw new ArgumentException("partUri");
        }
开发者ID:twxstar,项目名称:npoi,代码行数:12,代码来源:ZipPackage.cs

示例5: AddRelationship

        /**
         * Add a relationship to a part (except relationships part).
         * <p>
         * Check rule M1.25: The Relationships part shall not have relationships to
         * any other part. Package implementers shall enforce this requirement upon
         * the attempt to create such a relationship and shall treat any such
         * relationship as invalid.
         * </p>
         * @param targetPartName
         *            Name of the target part. This one must be relative to the
         *            source root directory of the part.
         * @param targetMode
         *            Mode [Internal|External].
         * @param relationshipType
         *            Type of relationship.
         * @param id
         *            Relationship unique id.
         * @return The newly created and added relationship
         * 
         * @throws InvalidFormatException
         *             If the URI point to a relationship part URI.
         * @see org.apache.poi.OpenXml4Net.opc.RelationshipSource#AddRelationship(org.apache.poi.OpenXml4Net.opc.PackagePartName,
         *      org.apache.poi.OpenXml4Net.opc.TargetMode, java.lang.String, java.lang.String)
         */
        public PackageRelationship AddRelationship(PackagePartName targetPartName,
                TargetMode targetMode, String relationshipType, String id)
        {
            container.ThrowExceptionIfReadOnly();

            if (targetPartName == null)
            {
                throw new ArgumentException("targetPartName");
            }
            //if (targetMode == null)
            //{
            //    throw new ArgumentException("targetMode");
            //}
            if (relationshipType == null)
            {
                throw new ArgumentException("relationshipType");
            }

            if (this.IsRelationshipPart || targetPartName.IsRelationshipPartURI())
            {
                throw new InvalidOperationException(
                        "Rule M1.25: The Relationships part shall not have relationships to any other part.");
            }

            if (relationships == null)
            {
                relationships = new PackageRelationshipCollection();
            }

            return relationships.AddRelationship(targetPartName.URI,
                    targetMode, relationshipType, id);
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:56,代码来源:PackagePart.cs

示例6: RemoveContentType

        /**
         * <p>
         * Delete a content type based on the specified part name. If the specified
         * part name is register with an override content type, then this content
         * type is remove, else the content type is remove in the default content
         * type list if it exists and if no part is associated with it yet.
         * </p><p>
         * Check rule M2.4: The package implementer shall require that the Content
         * Types stream contain one of the following for every part in the package:
         * One matching Default element One matching Override element Both a
         * matching Default element and a matching Override element, in which case
         * the Override element takes precedence.
         * </p>
         * @param partName
         *            The part URI associated with the override content type to
         *            delete.
         * @exception InvalidOperationException
         *                Throws if
         */
        public void RemoveContentType(PackagePartName partName)
        {
            if (partName == null)
                throw new ArgumentException("partName");

            /* Override content type */
            if (this.overrideContentType != null
                    && this.overrideContentType.ContainsKey(partName))
            {
                // Remove the override definition for the specified part.
                this.overrideContentType.Remove(partName);
                return;
            }

            /* Default content type */
            String extensionToDelete = partName.Extension;
            bool deleteDefaultContentTypeFlag = true;
            if (this.container != null)
            {
                try
                {
                    foreach (PackagePart part in this.container.GetParts())
                    {
                        if (!part.PartName.Equals(partName) && part.PartName.Extension
                                        .Equals(extensionToDelete, StringComparison.InvariantCultureIgnoreCase))
                        {
                            deleteDefaultContentTypeFlag = false;
                            break;
                        }
                    }
                }
                catch (InvalidFormatException e)
                {
                    throw new InvalidOperationException(e.Message);
                }
            }

            // Remove the default content type, no other part use this content type.
            if (deleteDefaultContentTypeFlag)
            {
                this.defaultContentType.Remove(extensionToDelete);
            }

            /*
             * Check rule 2.4: The package implementer shall require that the
             * Content Types stream contain one of the following for every part in
             * the package: One matching Default element One matching Override
             * element Both a matching Default element and a matching Override
             * element, in which case the Override element takes precedence.
             */
            if (this.container != null)
            {
                try
                {
                    foreach (PackagePart part in this.container.GetParts())
                    {
                        if (!part.PartName.Equals(partName)
                                && this.GetContentType(part.PartName) == null)
                            throw new InvalidOperationException(
                                    "Rule M2.4 is not respected: Nor a default element or override element is associated with the part: "
                                            + part.PartName.Name);
                    }
                }
                catch (InvalidFormatException e)
                {
                    throw new InvalidOperationException(e.Message);
                }
            }
        }
开发者ID:age-soft,项目名称:npoi,代码行数:88,代码来源:ContentTypeManager.cs

示例7: AddContentType

 /**
  * Build association extention-> content type (will be stored in
  * [Content_Types].xml) for example ContentType="image/png" Extension="png"
  * <p>
  * [M2.8]: When adding a new part to a package, the package implementer
  * shall ensure that a content type for that part is specified in the
  * Content Types stream; the package implementer shall perform the steps
  * described in &#167;9.1.2.3:
  * </p><p>
  * 1. Get the extension from the part name by taking the substring to the
  * right of the rightmost occurrence of the dot character (.) from the
  * rightmost segment.
  * </p><p>
  * 2. If a part name has no extension, a corresponding Override element
  * shall be added to the Content Types stream.
  * </p><p>
  * 3. Compare the resulting extension with the values specified for the
  * Extension attributes of the Default elements in the Content Types stream.
  * The comparison shall be case-insensitive ASCII.
  * </p><p>
  * 4. If there is a Default element with a matching Extension attribute,
  * then the content type of the new part shall be compared with the value of
  * the ContentType attribute. The comparison might be case-sensitive and
  * include every character regardless of the role it plays in the
  * content-type grammar of RFC 2616, or it might follow the grammar of RFC
  * 2616.
  * </p><p>
  * a. If the content types match, no further action is required.
  * </p><p>
  * b. If the content types do not match, a new Override element shall be
  * added to the Content Types stream. .
  * </p><p>
  * 5. If there is no Default element with a matching Extension attribute, a
  * new Default element or Override element shall be added to the Content
  * Types stream.
  * </p>
  */
 public void AddContentType(PackagePartName partName, String contentType)
 {
     bool defaultCTExists = false;
     String extension = partName.Extension.ToLower();
     if ((extension.Length == 0)
             || (this.defaultContentType.ContainsKey(extension) && !(defaultCTExists = this.defaultContentType
                     .ContainsValue(contentType))))
         this.AddOverrideContentType(partName, contentType);
     else if (!defaultCTExists)
         this.AddDefaultContentType(extension, contentType);
 }
开发者ID:age-soft,项目名称:npoi,代码行数:48,代码来源:ContentTypeManager.cs

示例8: RemovePartImpl

 /**
  * Core method to delete a package part. This method must be implemented by
  * the subclass.
  * 
  * @param PartName
  *            The URI of the part to delete.
  */
 protected abstract void RemovePartImpl(PackagePartName PartName);
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:8,代码来源:OPCPackage.cs

示例9: CreatePartImpl

 /**
  * Core method to Create a package part. This method must be implemented by
  * the subclass.
  * 
  * @param PartName
  *            URI of the part to Create.
  * @param contentType
  *            Content type of the part to Create.
  * @return The newly Created package part.
  */
 protected abstract PackagePart CreatePartImpl(PackagePartName PartName,
         String contentType, bool loadRelationships);
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:12,代码来源:OPCPackage.cs

示例10: AddRelationship

        /**
         * Add a relationship to the package (except relationships part).
         * 
         * Check rule M4.1 : The format designer shall specify and the format
         * producer shall Create at most one core properties relationship for a
         * package. A format consumer shall consider more than one core properties
         * relationship for a package to be an error. If present, the relationship
         * shall target the Core Properties part.
         * 
         * Check rule M1.25: The Relationships part shall not have relationships to
         * any other part. Package implementers shall enforce this requirement upon
         * the attempt to Create such a relationship and shall treat any such
         * relationship as invalid.
         * 
         * @param targetPartName
         *            Target part name.
         * @param targetMode
         *            Target mode, either Internal or External.
         * @param relationshipType
         *            Relationship type.
         * @param relID
         *            ID of the relationship.
         * @see PackageRelationshipTypes
         */
        public PackageRelationship AddRelationship(PackagePartName targetPartName,
                TargetMode targetMode, String relationshipType, String relID)
        {
            /* Check OPC compliance */

            // Check rule M4.1 : The format designer shall specify and the format
            // producer
            // shall Create at most one core properties relationship for a package.
            // A format consumer shall consider more than one core properties
            // relationship for a package to be an error. If present, the
            // relationship shall target the Core Properties part.
            if (relationshipType.Equals(PackageRelationshipTypes.CORE_PROPERTIES)
                    && this.packageProperties != null)
                throw new InvalidOperationException(
                        "OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.");

            /*
             * Check rule M1.25: The Relationships part shall not have relationships
             * to any other part. Package implementers shall enforce this
             * requirement upon the attempt to Create such a relationship and shall
             * treat any such relationship as invalid.
             */
            if (targetPartName.IsRelationshipPartURI())
            {
                throw new InvalidOperationException(
                        "Rule M1.25: The Relationships part shall not have relationships to any other part.");
            }

            /* End OPC compliance */

            EnsureRelationships();
            PackageRelationship retRel = relationships.AddRelationship(
                    targetPartName.URI, targetMode, relationshipType, relID);
            this.isDirty = true;
            return retRel;
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:60,代码来源:OPCPackage.cs

示例11: ContainPart

 /**
  * Check if a part already exists in this package from its name.
  * 
  * @param PartName
  *            Part name to check.
  * @return <i>true</i> if the part is logically Added to this package, else
  *         <i>false</i>.
  */
 public bool ContainPart(PackagePartName partName)
 {
     return (this.GetPart(partName) != null);
 }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:12,代码来源:OPCPackage.cs

示例12: DeletePartRecursive

        /**
         * Delete the part with the specified name and all part listed in its
         * associated relationships part if one exists. This process is recursively
         * apply to all parts in the relationships part of the specified part.
         * Prefer the use of this method to delete a part in the package, compare to
         * the Remove() methods that don't Remove associated relationships part.
         * 
         * @param PartName
         *            Name of the part to delete
         */
        public void DeletePartRecursive(PackagePartName partName)
        {
            if (partName == null || !this.ContainPart(partName))
                throw new ArgumentException("PartName");

            PackagePart partToDelete = this.GetPart(partName);
            // Remove the part
            this.RemovePart(partName);
            // Remove all relationship parts associated
            try
            {
                foreach (PackageRelationship relationship in partToDelete
                        .Relationships)
                {
                    PackagePartName targetPartName = PackagingUriHelper
                            .CreatePartName(PackagingUriHelper.ResolvePartUri(
                                    partName.URI, relationship.TargetUri));
                    this.DeletePartRecursive(targetPartName);
                }
            }
            catch (InvalidFormatException e)
            {
                logger.Log(POILogger.WARN, "An exception occurs while deleting part '"
                        + partName.Name
                        + "'. Some parts may remain in the package. - "
                        + e.Message);
                return;
            }
            // Remove the relationships part
            PackagePartName relationshipPartName = PackagingUriHelper
                    .GetRelationshipPartName(partName);
            if (relationshipPartName != null && ContainPart(relationshipPartName))
                this.RemovePart(relationshipPartName);
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:44,代码来源:OPCPackage.cs

示例13: DeletePart

        /**
         * Delete the part with the specified name and its associated relationships
         * part if one exists. Prefer the use of this method to delete a part in the
         * package, compare to the Remove() methods that don't Remove associated
         * relationships part.
         * 
         * @param PartName
         *            Name of the part to delete
         */
        public void DeletePart(PackagePartName partName)
        {
            if (partName == null)
                throw new ArgumentException("PartName");

            // Remove the part
            this.RemovePart(partName);
            // Remove the relationships part
            this.RemovePart(PackagingUriHelper.GetRelationshipPartName(partName));
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:19,代码来源:OPCPackage.cs

示例14: PackagingUriHelper

        /* Static initialization */
        static PackagingUriHelper()
        {
            RELATIONSHIP_PART_SEGMENT_NAME = "_rels";
            RELATIONSHIP_PART_EXTENSION_NAME = ".rels";
            FORWARD_SLASH_CHAR = '/';
            FORWARD_SLASH_STRING = "/";
            PACKAGE_PROPERTIES_SEGMENT_NAME = "docProps";
            PACKAGE_CORE_PROPERTIES_NAME = "core.xml";

            // Make Uri
            Uri uriPACKAGE_ROOT_URI = null;
            Uri uriPACKAGE_RELATIONSHIPS_ROOT_URI = null;
            Uri uriPACKAGE_PROPERTIES_URI = null;

            uriPACKAGE_ROOT_URI = new Uri("/",UriKind.Relative);
            uriPACKAGE_RELATIONSHIPS_ROOT_URI = new Uri(FORWARD_SLASH_CHAR
                    + RELATIONSHIP_PART_SEGMENT_NAME + FORWARD_SLASH_CHAR
                    + RELATIONSHIP_PART_EXTENSION_NAME, UriKind.Relative);
            packageRootUri = new Uri("/", UriKind.Relative);
            uriPACKAGE_PROPERTIES_URI = new Uri(FORWARD_SLASH_CHAR
                    + PACKAGE_PROPERTIES_SEGMENT_NAME + FORWARD_SLASH_CHAR
                    + PACKAGE_CORE_PROPERTIES_NAME, UriKind.Relative);

            PACKAGE_ROOT_URI = uriPACKAGE_ROOT_URI;
            PACKAGE_RELATIONSHIPS_ROOT_URI = uriPACKAGE_RELATIONSHIPS_ROOT_URI;
            CORE_PROPERTIES_URI = uriPACKAGE_PROPERTIES_URI;

            // Make part name from previous Uri
            PackagePartName tmpPACKAGE_ROOT_PART_NAME = null;
            PackagePartName tmpPACKAGE_RELATIONSHIPS_ROOT_PART_NAME = null;
            PackagePartName tmpCORE_PROPERTIES_URI = null;
            try
            {
                tmpPACKAGE_RELATIONSHIPS_ROOT_PART_NAME = CreatePartName(PACKAGE_RELATIONSHIPS_ROOT_URI);
                tmpCORE_PROPERTIES_URI = CreatePartName(CORE_PROPERTIES_URI);
                tmpPACKAGE_ROOT_PART_NAME = new PackagePartName(PACKAGE_ROOT_URI,
                        false);
            }
            catch (InvalidFormatException)
            {
                // Should never happen in production as all data are fixed
            }
            PACKAGE_RELATIONSHIPS_ROOT_PART_NAME = tmpPACKAGE_RELATIONSHIPS_ROOT_PART_NAME;
            CORE_PROPERTIES_PART_NAME = tmpCORE_PROPERTIES_URI;
            PACKAGE_ROOT_PART_NAME = tmpPACKAGE_ROOT_PART_NAME;
        }
开发者ID:WPG,项目名称:npoi,代码行数:47,代码来源:PackagingUriHelper.cs

示例15: PackagePropertiesPart

	/**
	 * Constructor.
	 * 
	 * @param pack
	 *            Container package.
	 * @param partName
	 *            Name of this part.
	 * @throws InvalidFormatException
	 *             Throws if the content is invalid.
	 */
	public PackagePropertiesPart(OPCPackage pack, PackagePartName partName)
        :base(pack, partName, ContentTypes.CORE_PROPERTIES_PART)
	{
		
	}
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:15,代码来源:PackagePropertiesPart.cs


注:本文中的PackagePartName类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。