Package::CreatePart Method (Uri, String)
Creates a new uncompressed part with a given URI and content type.
Assembly: WindowsBase (in WindowsBase.dll)
Parameters
- partUri
- Type: System::Uri
The uniform resource identifier (URI) of the new part.
- contentType
- Type: System::String
The content type of the data stream.
| Exception | Condition |
|---|---|
| ArgumentNullException | partUri or contentType is nullptr. |
| ArgumentException | partUri is not a valid PackagePart URI. |
| InvalidOperationException | A part with the specified partUri is already present in the package. |
| ObjectDisposedException | |
| IOException | The package is read-only (a new part cannot be added). |
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.
The part CompressionOption is CompressionOption::NotCompressed.
For additional information about package parts, see section 1.1 in the Open Packaging Conventions (OPC) specification available for download at http://go.microsoft.com/fwlink/?LinkID=71255.
Notes to InheritorsCreatePart internally calls the derived class's 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.
Windows 7, Windows Vista SP1 or later, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.