.NET Framework Class Library
PackUriHelper..::.CreatePartUri Method

Creates a formatted PackagePart URI.

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

Visual Basic (Declaration)
Public Shared Function CreatePartUri ( _
    partUri As Uri _
) As Uri
Visual Basic (Usage)
Dim partUri As Uri
Dim returnValue As Uri

returnValue = PackUriHelper.CreatePartUri(partUri)
C#
public static Uri CreatePartUri(
    Uri partUri
)
Visual C++
public:
static Uri^ CreatePartUri(
    Uri^ partUri
)
JScript
public static function CreatePartUri(
    partUri : Uri
) : Uri
XAML
You cannot use methods in XAML.

Parameters

partUri
Type: System..::.Uri
The URI of the PackagePart within the package.

Return Value

Type: System..::.Uri
A formatted PackagePart URI.
Remarks

The URI of a PackagePart is always referenced from the Package root.

The returned PackagePart URI is an absolute path that always starts with "/" and conforms to the syntax defined in the Open Packaging Conventions Specification.

The following table illustrates sample cases for CreatePartUri.

 partUri

 Returned Part URI 

 picture1.jpg 

 /picture1.jpg 

 /picture2.jpg 

 /picture2.jpg 

 a/mydoc.xaml 

 /a/mydoc.xaml 

 /b/bar.xaml 

 /b/bar.xaml 

Examples

The following example shows how to use the CreatePartUri method to define relative URIs for PackagePart elements.

C#
// Convert system path and file names to Part URIs. In this example
// Uri partUriDocument /* /Content/Document.xml */ =
//     PackUriHelper.CreatePartUri(
//         new Uri("Content\Document.xml", UriKind.Relative));
// Uri partUriResource /* /Resources/Image1.jpg */ =
//     PackUriHelper.CreatePartUri(
//         new Uri("Resources\Image1.jpg", UriKind.Relative));
Uri partUriDocument = PackUriHelper.CreatePartUri(
                          new Uri(documentPath, UriKind.Relative));
Uri partUriResource = PackUriHelper.CreatePartUri(
                          new Uri(resourcePath, UriKind.Relative));
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Tags :


Page view tracker