CustomPartCollection Class
Represents a collection of CustomPart objects.
Inheritance Hierarchy
SystemObject
  Aspose.Words.MarkupCustomPartCollection

Namespace: Aspose.Words.Markup
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
Syntax
public class CustomPartCollection : IEnumerable<CustomPart>, 
	IEnumerable

The CustomPartCollection type exposes the following members.

Constructors
  NameDescription
Public methodCustomPartCollection
Initializes a new instance of the CustomPartCollection class
Properties
  NameDescription
Public propertyCode exampleCount
Gets the number of elements contained in the collection.
Public propertyCode exampleItem
Gets or sets an item at the specified index.
Methods
  NameDescription
Public methodCode exampleAdd
Adds an item to the collection.
Public methodCode exampleClear
Removes all elements from the collection.
Public methodCode exampleClone
Makes a deep copy of this collection and its items.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodCode exampleGetEnumerator
Returns an enumerator object that can be used to iterate over all items in the collection.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodCode exampleRemoveAt
Removes an item at the specified index.
Public methodToString (Inherited from Object.)
Remarks

You do not normally need to create instances of this class. You access custom parts related to the OOXML package via the PackageCustomParts property.

Examples
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 + "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