CustomPart Class
Represents a custom (arbitrary content) part, that is not defined by the ISO/IEC 29500 standard.
Inheritance Hierarchy
SystemObject
  Aspose.Words.MarkupCustomPart

Namespace: Aspose.Words.Markup
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
Syntax
public class CustomPart

The CustomPart type exposes the following members.

Constructors
  NameDescription
Public methodCustomPart
Initializes a new instance of the CustomPart class
Properties
  NameDescription
Public propertyCode exampleContentType
Specifies the content type of this custom part.
Public propertyCode exampleData
Contains the data of this custom part.
Public propertyCode exampleIsExternal
False if this custom part is stored inside the OOXML package. True if this custom part is an external target.
Public propertyCode exampleName
Gets or sets this part's absolute name within the OOXML package or the target URL.
Public propertyCode exampleRelationshipType
Gets or sets the relationship type from the parent part to this custom part.
Methods
  NameDescription
Public methodCode exampleClone
Makes a "deep enough" copy of the object. Does not duplicate the bytes of the Data value.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)
Remarks

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 http://blogs.msdn.com/dmahugh/archive/2006/11/25/arbitrary-content-in-an-opc-package.aspx

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.

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