Поделиться через


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

Adds a new part of type T.

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

Syntax

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

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

Type Parameters

  • T
    The class of the part.

Parameters

  • 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.

Exceptions

Exception Condition
OpenXmlPackageException

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

ArgumentOutOfRangeException

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

ArgumentNullException

Thrown when "contentType" is null reference.

Remarks

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

See Also

Reference

OpenXmlPartContainer Class

OpenXmlPartContainer Members

AddNewPart Overload

DocumentFormat.OpenXml.Packaging Namespace