This documentation is archived and is not being maintained.

PackUriHelper.Create Method (Uri, Uri)

Creates a pack URI given a Package URI and the URI of a part in the package.

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

public static Uri Create (
	Uri packageUri,
	Uri partUri
public static Uri Create (
	Uri packageUri, 
	Uri partUri
public static function Create (
	packageUri : Uri, 
	partUri : Uri
) : Uri
You cannot use methods in XAML.



The URI of the Package.


The URI of the PackagePart in the package.

Return Value

The pack URI of the given PackagePart.

Exception typeCondition


packageUri is a null reference (Nothing in Visual Basic).


packageUri is not an absolute URI; orpartUri is not a valid part URI syntax.

packageUri may not be specified as null or empty.

If partUri is a null reference (Nothing in Visual Basic) the returned pack URI points to the package.

The following table illustrates sample cases for the Create method:



 Returned pack URI 
















Composing a pack URI is a multi-step process, For example, one step in forming a pack URI is to replace the forward slash (/) characters of the packageUri with commas (,).

For more information on string conversion and how pack URIs are formed, see Appendix A.4 "String Conversion Examples" and Appendix B.3 "Composing a Pack URI" in the Open Packaging Conventions specification available for download at

The following example shows how to use the Create method to define a pack URI that references a package. For the full sample, see the Rights Managed Package Publish Sample.

// ------------------------ GetFixedDocument --------------------------
/// <summary>
///   Returns the fixed document at a given URI within
///   the currently open XPS package.</summary>
/// <param name="fixedDocUri">
///   The URI of the fixed document to return.</param>
/// <returns>
///   The fixed document at a given URI
///   within the current XPS package.</returns>
private FixedDocument GetFixedDocument(Uri fixedDocUri)
    FixedDocument fixedDocument = null;

    // Create the URI for the fixed document within the package. The URI
    // is used to set the Parser context so fonts & other items can load.
    Uri tempUri = new Uri(_xpsDocumentPath, UriKind.RelativeOrAbsolute);
    ParserContext parserContext = new ParserContext();
    parserContext.BaseUri = PackUriHelper.Create(tempUri);

    // Retreive the fixed document.
    PackagePart fixedDocPart = _xpsPackage.GetPart(fixedDocUri);
    if (fixedDocPart != null)
        object fixedObject =
            XamlReader.Load(fixedDocPart.GetStream(), parserContext);
        if (fixedObject != null)
            fixedDocument = fixedObject as FixedDocument;

    return fixedDocument;
}// end:GetFixedDocument()

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