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

Adds a new part of type T.

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


Public Overridable Function AddNewPart(Of T As OpenXmlPart) ( _
    contentType As String, _
    id As String _
) As T
Dim instance As OpenXmlPartContainer
Dim contentType As String
Dim id As String
Dim returnValue As T

returnValue = instance.AddNewPart(contentType, _
public virtual T AddNewPart<T>(
    string contentType,
    string id
where T : OpenXmlPart

Type Parameters

  • T
    The class of the part.


  • contentType
    Type: System.String
    The content type of the part. Must match the defined content type if the part is fixed content type.
  • id
    Type: System.String
    The relationship id. The id will be automaticly generated if this param is null.

Return Value

Type: T
The added part.


Exception Condition

When the part is not allowed to be referenced by this part.


When the part is fixed content type and the passed in contentType does not match the defined content type.


Thrown when "contentType" is null reference.


Mainly used for adding not-fixed content type part - ImagePart, VideoPart, AudioPart, etc

See Also


OpenXmlPartContainer Class

OpenXmlPartContainer Members

AddNewPart Overload

DocumentFormat.OpenXml.Packaging Namespace