Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Package.GetParts Method

Returns a collection of all the parts in the package.

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

public PackagePartCollection GetParts ()
public PackagePartCollection GetParts ()
public function GetParts () : PackagePartCollection
You cannot use methods in XAML.

Return Value

A collection of all the PackagePart elements that are contained in the package.

Exception typeCondition

ObjectDisposedException

The package is not open (Dispose or Close has been called).

IOException

The package is write-only.

GetParts returns a collection of all parts that are contained in the package including PackageRelationship parts.

GetParts will never return a null reference (Nothing in Visual Basic); however, the returned collection will contain zero elements if the package contains no parts.

By default, a ZipPackage subclass implementation of the abstract Package base class is provided and used. In the default operation, GetParts calls the GetPartsCore method of the ZipPackage class to return the parts from a ZIP file.

For more information about packages and 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 Implementers: GetParts internally calls the derived class GetPartsCore method to actually flush the part based on the physical format implemented in the subclass.

The following example shows how to use the GetParts method to obtain a collection of the parts that are contained in a Package. For the complete program source code, see Creating a Package with a Digital Signature Sample.

// Create a list of all the part URIs in the package to sign
// (GetParts() also includes PackageRelationship parts).
System.Collections.Generic.List<Uri> toSign =
    new System.Collections.Generic.List<Uri>();
foreach (PackagePart packagePart in package.GetParts())
{
    // Add all package parts to the list for signing.
    toSign.Add(packagePart.Uri);
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft