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

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
Syntax
public CustomPartCollection PackageCustomParts { get; set; }

Property Value

Type: CustomPartCollection
Remarks

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.

Examples
Shows how to open a document with custom parts and access them.
[C#]

// 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 + "Document.PackageCustomParts.docx");
Assert.AreEqual(2, doc.PackageCustomParts.Count);

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

// Add the clone to the collection
doc.PackageCustomParts.Add(clonedPart);

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

// 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}");
        if (enumerator.Current.IsExternal)
        {
            Console.WriteLine("\tSourced from outside the document");
        }
        else
        {
            Console.WriteLine($"\tSourced from within the document, length: {enumerator.Current.Data.Length} bytes");
        }
        index++;
    }
}


// Delete parts one at a time based on index
doc.PackageCustomParts.RemoveAt(2);
Assert.AreEqual(2, doc.PackageCustomParts.Count);

// Delete all parts
doc.PackageCustomParts.Clear();
Assert.AreEqual(0, doc.PackageCustomParts.Count);
See Also