PackUriHelper.CreatePartUri Method (Uri)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a formatted PackagePart URI.

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

Public Shared Function CreatePartUri (
	partUri As Uri
) As Uri

Parameters

partUri
Type: System.Uri

The URI of the PackagePart within the package.

Return Value

Type: System.Uri

A formatted PackagePart URI.

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 

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

' Convert system path and file names to Part URIs. In this example
' Dim partUriDocument as Uri /* /Content/Document.xml */ =
'     PackUriHelper.CreatePartUri(
'         New Uri("Content\Document.xml", UriKind.Relative))
' Dim partUriResource as Uri /* /Resources/Image1.jpg */ =
'     PackUriHelper.CreatePartUri(
'         New Uri("Resources\Image1.jpg", UriKind.Relative))
Dim partUriDocument As Uri = PackUriHelper.CreatePartUri(New Uri(documentPath, UriKind.Relative))
Dim partUriResource As Uri = PackUriHelper.CreatePartUri(New Uri(resourcePath, UriKind.Relative))

.NET Framework
Available since 3.0
Return to top
Show: