CustomPart class

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

public class CustomPart


Name Description
CustomPart() The default constructor.


Name Description
ContentType { get; set; } Specifies the content type of this custom part.
Data { get; set; } Contains the data of this custom part.
IsExternal { get; set; } False if this custom part is stored inside the OOXML package. True if this custom part is an external target.
Name { get; set; } Gets or sets this part’s absolute name within the OOXML package or the target URL.
RelationshipType { get; set; } Gets or sets the relationship type from the parent part to this custom part.


Name Description
Clone() Makes a “deep enough” copy of the object. Does not duplicate the bytes of the Data value.


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 access a document’s arbitrary custom parts collection.

Document doc = new Document(MyDir + "Custom parts OOXML package.docx");

Assert.AreEqual(2, doc.PackageCustomParts.Count);

// Clone the second part, then add the clone to the collection.
CustomPart clonedPart = doc.PackageCustomParts[1].Clone();
Assert.AreEqual(3, doc.PackageCustomParts.Count);

// Enumerate over the collection and print every part.
using (IEnumerator<CustomPart> enumerator = doc.PackageCustomParts.GetEnumerator())
    int index = 0;
    while (enumerator.MoveNext())
        Console.WriteLine($"Part index {index}:");
        Console.WriteLine($"\tContent type:\t\t{enumerator.Current.ContentType}");
        Console.WriteLine($"\tRelationship type:\t{enumerator.Current.RelationshipType}");
        Console.WriteLine(enumerator.Current.IsExternal ?
            "\tSourced from outside the document" :
            $"\tStored within the document, length: {enumerator.Current.Data.Length} bytes");

// We can remove elements from this collection individually, or all at once.

Assert.AreEqual(2, doc.PackageCustomParts.Count);


Assert.AreEqual(0, doc.PackageCustomParts.Count);

See Also