Document.PackageCustomParts property

Gets or sets the collection of custom parts (arbitrary content) that are linked to the OOXML package using “unknown relationships”.

public CustomPartCollection PackageCustomParts { get; set; }


Do not confuse these custom parts with Custom XML Data. If you need to access Custom XML parts, use the CustomXmlParts property.

This collection contains OOXML parts whose parent is the OOXML package and they targets are of an “unknown relationship”. For more information see CustomPart.

Aspose.Words loads and saves custom parts into OOXML documents only.

This property cannot be null.


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