Прочетете на английски Редактиране

Споделяне чрез


PackUriHelper.CreatePartUri(Uri) Method

Definition

Creates a formatted PackagePart URI.

C#
public static Uri CreatePartUri(Uri partUri);

Parameters

partUri
Uri

The URI of the PackagePart within the package.

Returns

Uri

A formatted PackagePart URI.

Exceptions

partUri is null.

partUri is not an absolute Uri.

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));

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

Applies to

Продукт Версии
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also