CustomPart Class

Represents a custom (arbitrary content) part, that is not defined by the ISO/IEC 29500 standard.

Inheritance Hierarchy


Namespace:  Aspose.Words.Markup
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public class CustomPart

The CustomPart type exposes the following members.


Public methodCustomPart
Initializes a new instance of the CustomPart class


Public propertyCode exampleContentType
Specifies the content type of this custom part.
Public propertyCode exampleData
Contains the data of this custom part.
Public propertyCode exampleIsExternal
False if this custom part is stored inside the OOXML package. True if this custom part is an external target.
Public propertyCode exampleName
Gets or sets this part's absolute name within the OOXML package or the target URL.
Public propertyCode exampleRelationshipType
Gets or sets the relationship type from the parent part to this custom part.


Public methodCode exampleClone
Makes a "deep enough" copy of the object. Does not duplicate the bytes of the Data value.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)


This class represents an OOXML part that is a target of an "unknown relationship". All relationships not defined within ISO/IEC 29500 are considered "unknown relationships". Unknown relationships are permitted within an Office Open XML document provided that they conform to relationship markup guidelines.

Microsoft Word preserves custom parts during open/save cycles. Some additional info can be found here

Aspose.Words also roundtrips custom parts and in addition, allows to programmatically access such parts via the CustomPart and CustomPartCollection objects.

Do not confuse custom parts with Custom XML Data. Use CustomXmlPart if you need to access Custom XML Data.


Shows how to open a document with custom parts and access them.
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Document doc = new Document(MyDir + "Custom parts OOXML package.docx");

// Clone the second part
CustomPart clonedPart = doc.PackageCustomParts[1].Clone();

// Add the clone to the collection

// Use an enumerator to print information about the contents of each part 
using (IEnumerator<CustomPart> enumerator = doc.PackageCustomParts.GetEnumerator())
    int index = 0;
    while (enumerator.MoveNext())
        Console.WriteLine($"Part index {index}:");
        Console.WriteLine($"\tName: {enumerator.Current.Name}");
        Console.WriteLine($"\tContentType: {enumerator.Current.ContentType}");
        Console.WriteLine($"\tRelationshipType: {enumerator.Current.RelationshipType}");
            ? "\tSourced from outside the document"
            : $"\tSourced from within the document, length: {enumerator.Current.Data.Length} bytes");

// The parts collection can have individual entries removed or be cleared like this

See Also