CreatePart Method

Package.CreatePart Method


Creates a new package part.

Namespace:   System.IO.Packaging
Assembly:  WindowsBase (in WindowsBase.dll)

System_CAPS_pubmethodCreatePart(Uri, String)

Creates a new uncompressed part with a given URI and content type.

System_CAPS_pubmethodCreatePart(Uri, String, CompressionOption)

Creates a new part with a given URI, content type, and compression option.

CreatePart initializes an empty Stream for the new part. The PackagePart.GetStream method can be used to obtain a reference to the stream instance associated with the part.

For more information about package parts, see section 1.1 of the Open Packaging Conventions (OPC) specification available for download at

Notes to Inheritors:

CreatePart internally calls the derived class CreatePartCore method to actually create the part based on the physical format implemented in the derived class.

The following example shows how to create a new PackagePart and then store data into the part. For the complete sample, see Writing a Package Sample.

// Add the Document part to the Package
PackagePart packagePartDocument =

// Copy the data to the Document Part
using (FileStream fileStream = new FileStream(
       documentPath, FileMode.Open, FileAccess.Read))
    CopyStream(fileStream, packagePartDocument.GetStream());
}// end:using(fileStream) - Close and dispose fileStream.
Return to top
© 2015 Microsoft