OpenXmlPartContainer.AddPart<T> Method (T, String)

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Adds the part to the document with a given relationship identifier (ID). Must use the returned part to operate the part added to the document.

Namespace:  DocumentFormat.OpenXml.Packaging
Assembly:  DocumentFormat.OpenXml (in DocumentFormat.OpenXml.dll)

Syntax

'Declaration
Public Overridable Function AddPart(Of T As OpenXmlPart) ( _
    part As T, _
    id As String _
) As T
'Usage
Dim instance As OpenXmlPartContainer
Dim part As T
Dim id As String
Dim returnValue As T

returnValue = instance.AddPart(part, id)
public virtual T AddPart<T>(
    T part,
    string id
)
where T : OpenXmlPart

Type Parameters

  • T
    Derived class from OpenXmlPart.

Parameters

  • part
    Type: T
    Specifies the part to be added to the document.
  • id
    Type: System.String
    Specifies a unique relationship identifier.

Return Value

Type: T
Returns the added part in the document. Different from the passed-in part.

Exceptions

Exception Condition
ArgumentNullException

Throws an exception when part" or the "id is null reference.

ArgumentOutOfRangeException

Throws an exception when the part is not allowed to be added.

OpenXmlPackageException

Throws an exception when one instance of same type part already exists and multiple instance of that type is not allowed.

See Also

Reference

OpenXmlPartContainer Class

OpenXmlPartContainer Members

AddPart Overload

DocumentFormat.OpenXml.Packaging Namespace