Package.CreatePart Method

Creates a new package part.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method CreatePart(Uri, String) Creates a new uncompressed part with a given URI and content type.
Public method CreatePart(Uri, String, CompressionOption) Creates a new part with a given URI, content type, and compression option.
Top

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 http://go.microsoft.com/fwlink/?LinkID=71255.

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 =
    package.CreatePart(partUriDocument,
                   System.Net.Mime.MediaTypeNames.Text.Xml);

// 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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft