OpenXmlPartContainer.AddNewPart Method

Definition

Overloads

AddNewPart<T>(String)

Adds a new part of type T.

AddNewPart<T>(String, String)

Adds a new part of type T.

AddNewPart<T>()

Adds a new part of type T.

AddNewPart<T>(String)

Adds a new part of type T.

C#
public T AddNewPart<T> (string id) where T : DocumentFormat.OpenXml.Packaging.OpenXmlPart, DocumentFormat.OpenXml.Packaging.IFixedContentTypePart;

Type Parameters

T

The class of the part.

Parameters

id
String

The relationship id.

Returns

T

The added part.

Exceptions

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

Applies to

DocumentFormat.OpenXml 3.0.1 and other versions
Product Versions
DocumentFormat.OpenXml 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 2.12.0, 2.12.1, 2.12.2, 2.12.3, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.17.1, 2.18.0, 2.19.0, 2.20.0, 3.0.0, 3.0.1

AddNewPart<T>(String, String)

Adds a new part of type T.

C#
public virtual T AddNewPart<T> (string contentType, string id) where T : DocumentFormat.OpenXml.Packaging.OpenXmlPart;
C#
public virtual T AddNewPart<T> (string contentType, string? id = default) where T : DocumentFormat.OpenXml.Packaging.OpenXmlPart;

Type Parameters

T

The class of the part.

Parameters

contentType
String

The content type of the part. Must match the defined content type if the part is fixed content type.

id
String

The relationship id. The id will be automatically generated if this param is null.

Returns

T

The added part.

Exceptions

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.

Remarks

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

Applies to

DocumentFormat.OpenXml 3.0.1 and other versions
Product Versions
DocumentFormat.OpenXml 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 2.12.0, 2.12.1, 2.12.2, 2.12.3, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.17.1, 2.18.0, 2.19.0, 2.20.0, 3.0.0, 3.0.1

AddNewPart<T>()

Adds a new part of type T.

C#
public T AddNewPart<T> () where T : DocumentFormat.OpenXml.Packaging.OpenXmlPart, DocumentFormat.OpenXml.Packaging.IFixedContentTypePart;

Type Parameters

T

The class of the part.

Returns

T

The added part.

Exceptions

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

Applies to

DocumentFormat.OpenXml 3.0.1 and other versions
Product Versions
DocumentFormat.OpenXml 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 2.12.0, 2.12.1, 2.12.2, 2.12.3, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.17.1, 2.18.0, 2.19.0, 2.20.0, 3.0.0, 3.0.1