CustomPartCollection Class |
Namespace: Aspose.Words.Markup
The CustomPartCollection type exposes the following members.
Name | Description | |
---|---|---|
![]() | CustomPartCollection | Initializes a new instance of the CustomPartCollection class |
Name | Description | |
---|---|---|
![]() ![]() | Count |
Gets the number of elements contained in the collection.
|
![]() ![]() | Item |
Gets or sets an item at the specified index.
|
Name | Description | |
---|---|---|
![]() ![]() | Add |
Adds an item to the collection.
|
![]() ![]() | Clear |
Removes all elements from the collection.
|
![]() ![]() | Clone |
Makes a deep copy of this collection and its items.
|
![]() | Equals | (Inherited from Object.) |
![]() ![]() | GetEnumerator |
Returns an enumerator object that can be used to iterate over all items in the collection.
|
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | RemoveAt |
Removes an item at the specified index.
|
![]() | ToString | (Inherited from Object.) |
You do not normally need to create instances of this class. You access custom parts related to the OOXML package via the PackageCustomParts property.
// 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"); 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}"); Console.WriteLine(enumerator.Current.IsExternal ? "\tSourced from outside the document" : $"\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);