PackUriHelper.Create 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建新包 URI。
重载
| Create(Uri) | 
						 创建一个指向包的新包 URI。  | 
        	
| Create(Uri, Uri) | 
						 在给定 Package URI 和包中部件的 URI 的情况下创建包 URI。  | 
        	
| Create(Uri, Uri, String) | 
						 在给定 Package URI、包中部件的 URI 以及要追加的“#”片段的情况下创建包 URI。  | 
        	
注解
下表说明了 方法的示例用例 Create 。
packageUri | 
partUri | 
fragment | 
返回的包 URI | 
|---|---|---|---|
http://www.proseware.com/mypackage.pkg | 
/page1.xaml | #intro | pack://http:,www.proseware.com,mypackage.pkg/page1.xaml#intro | 
http://www.proseware.com/mypackage.pkg | 
/page2.xaml | null | pack://http:,www.proseware.com,mypackage.pkg/page2.xaml | 
http://www.proseware.com/mypackage.pkg | 
/a/page4.xaml | null | pack://http:,www.proseware.com,mypackage.pkg/a/page4.xaml | 
http://www.proseware.com/mypackage.pkg | 
/%41/%61.xml | null | pack://http:,,www.proseware.com,mypackage.pkg/A/a.xml | 
http://www.proseware.com/mypackage.pkg | 
/%25XY.xml | null | pack://http:,www.proseware.com,mypackage.pkg/%25XY.xml | 
http://www.proseware.com/mypackage.pkg | 
/a/page5.xaml | #summary | pack://http:,www.proseware.com,mypackage.pkg/a/page5.xaml#summary | 
http://www.proseware.com/packages.aspx?pkg04 | 
/page1.xaml | #intro | pack://http:,www.proseware.com,packages.aspx%3fpkg04/page1.xaml#intro | 
http://www.proseware.com/mypackage.pkg | 
null | null | pack://http:,www.proseware.com,mypackage.pkg | 
ftp://ftp.proseware.com/packages/mypackage1.abc | 
/a/mydoc.xaml | null | pack://ftp:,,ftp.proseware.com,packages,mypackage1.abc/a/mydoc.xaml | 
file:///d:/packages/mypackage2.pkg | 
/a/bar.xaml | #xref | pack://file:,,,d:,packages,mypackage2.pkg/a/bar.xaml#xref | 
编写包 URI 是一个多步骤过程。  例如,形成 pack URI 的一个步骤是将 的正斜杠 (/) 字符 packageUri 替换为逗号 (,) 。
有关字符串转换以及如何形成包 URI 的详细信息,请参阅规范和 许可证下载中可供下载的开放打包约定规范中的附录 A.4“字符串转换示例”和附录 B.3“撰写包 URI”。
Create(Uri)
创建一个指向包的新包 URI。
public:
 static Uri ^ Create(Uri ^ packageUri);
	public static Uri Create (Uri packageUri);
	static member Create : Uri -> Uri
	Public Shared Function Create (packageUri As Uri) As Uri
	参数
返回
由给定的 packageUri 引用的 Package 的包 URI。
例外
              packageUri 为 null。
              packageUri 不是绝对 URI。
示例
以下示例演示如何使用 Create 方法定义引用包的包 URI。
// ------------------------ 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);
    // Retrieve 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()
' ------------------------ 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 Function GetFixedDocument(ByVal fixedDocUri As Uri) As FixedDocument
    Dim fixedDocument As FixedDocument = Nothing
    ' 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.
    Dim tempUri As New Uri(_xpsDocumentPath, UriKind.RelativeOrAbsolute)
    Dim parserContext As New ParserContext()
    parserContext.BaseUri = PackUriHelper.Create(tempUri)
    ' Retrieve the fixed document.
    Dim fixedDocPart As PackagePart = _xpsPackage.GetPart(fixedDocUri)
    If fixedDocPart IsNot Nothing Then
        Dim fixedObject As Object = XamlReader.Load(fixedDocPart.GetStream(), parserContext)
        If fixedObject IsNot Nothing Then
            fixedDocument = TryCast(fixedObject, FixedDocument)
        End If
    End If
    Return fixedDocument
End Function ' end:GetFixedDocument()
    	注解
              packageUri 不能指定为 null 或为空。
下表说明了 的示例 Create用例。
packageUri | 
返回的包 URI | 
|---|---|
http://www.proseware.com/mypackage.pkg | 
pack://http:,www.proseware.com,mypackage.pkg | 
| ftp://ftp.proseware.com/packages/mypackage1.abc | pack://ftp:,,ftp.proseware.com,packages,mypackage1.abc | 
| file:///d:/packages/mypackage2.pkg | pack://file:,,,d:,packages,mypackage2.pkg | 
编写包 URI 是一个多步骤过程。  例如,形成 pack URI 的一个步骤是将 的正斜杠 (/) 字符 packageUri 替换为逗号 (,) 。
有关字符串转换以及如何形成包 URI 的详细信息,请参阅规范和 许可证下载中可供下载的开放打包约定规范中的附录 A.4“字符串转换示例”和附录 B.3“撰写包 URI”。
另请参阅
适用于
Create(Uri, Uri)
在给定 Package URI 和包中部件的 URI 的情况下创建包 URI。
public:
 static Uri ^ Create(Uri ^ packageUri, Uri ^ partUri);
	public static Uri Create (Uri packageUri, Uri partUri);
	public static Uri Create (Uri packageUri, Uri? partUri);
	static member Create : Uri * Uri -> Uri
	Public Shared Function Create (packageUri As Uri, partUri As Uri) As Uri
	参数
- partUri
 - Uri
 
包中 PackagePart 的 URI。
返回
给定 PackagePart 的包 URI。
例外
              packageUri 为 null。
示例
以下示例演示如何使用 Create(Uri) 方法定义引用包的包 URI。
// ------------------------ 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);
    // Retrieve 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()
' ------------------------ 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 Function GetFixedDocument(ByVal fixedDocUri As Uri) As FixedDocument
    Dim fixedDocument As FixedDocument = Nothing
    ' 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.
    Dim tempUri As New Uri(_xpsDocumentPath, UriKind.RelativeOrAbsolute)
    Dim parserContext As New ParserContext()
    parserContext.BaseUri = PackUriHelper.Create(tempUri)
    ' Retrieve the fixed document.
    Dim fixedDocPart As PackagePart = _xpsPackage.GetPart(fixedDocUri)
    If fixedDocPart IsNot Nothing Then
        Dim fixedObject As Object = XamlReader.Load(fixedDocPart.GetStream(), parserContext)
        If fixedObject IsNot Nothing Then
            fixedDocument = TryCast(fixedObject, FixedDocument)
        End If
    End If
    Return fixedDocument
End Function ' end:GetFixedDocument()
    	注解
              packageUri 不能指定为 null 或空。
如果 partUri 为 null,则返回的包 URI 指向包。
下表说明了 方法的示例用例 Create 。
packageUri | 
partUri | 
返回的包 URI | 
|---|---|---|
http://www.proseware.com/mypackage.pkg | 
/page2.xaml | pack://http:,www.proseware.com,mypackage.pkg/page2.xaml | 
http://www.proseware.com/mypackage.pkg | 
/a/page4.xaml | pack://http:,www.proseware.com,mypackage.pkg/a/page4.xaml | 
http://www.proseware.com/mypackage.pkg | 
/%41/%61.xml | pack://http:,,www.proseware.com,mypackage.pkg/A/a.xml | 
http://www.proseware.com/mypackage.pkg | 
/%25XY.xml | pack://http:,www.proseware.com,mypackage.pkg/%25XY.xml | 
http://www.proseware.com/mypackage.pkg | 
null | pack://http:,www.proseware.com,mypackage.pkg | 
| ftp://ftp.proseware.com/packages/mypackage1.abc | /a/mydoc.xaml | pack://ftp:,,ftp.proseware.com,packages,mypackage1.abc/a/mydoc.xaml | 
| file:///d:/packages/mypackage2.pkg | /a/bar.xaml | pack://file:,,,d:,packages,mypackage2.pkg/a/bar.xaml | 
编写包 URI 是一个多步骤过程。  例如,形成 pack URI 的一个步骤是将 的正斜杠 (/) 字符 packageUri 替换为逗号 (,) 。
有关字符串转换以及如何形成包 URI 的详细信息,请参阅规范和 许可证下载中可供下载的开放打包约定规范中的附录 A.4“字符串转换示例”和附录 B.3“撰写包 URI”。
另请参阅
适用于
Create(Uri, Uri, String)
在给定 Package URI、包中部件的 URI 以及要追加的“#”片段的情况下创建包 URI。
public:
 static Uri ^ Create(Uri ^ packageUri, Uri ^ partUri, System::String ^ fragment);
	public static Uri Create (Uri packageUri, Uri partUri, string fragment);
	public static Uri Create (Uri packageUri, Uri? partUri, string? fragment);
	static member Create : Uri * Uri * string -> Uri
	Public Shared Function Create (packageUri As Uri, partUri As Uri, fragment As String) As Uri
	参数
- partUri
 - Uri
 
包中 PackagePart 的 URI。
- fragment
 - String
 
标识包部件中的元素的“#”引用。
返回
标识指定包、包部件和片段的包 URI。
例外
              packageUri 为 null。
示例
以下示例演示如何使用 Create(Uri) 方法定义引用包的包 URI。
// ------------------------ 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);
    // Retrieve 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()
' ------------------------ 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 Function GetFixedDocument(ByVal fixedDocUri As Uri) As FixedDocument
    Dim fixedDocument As FixedDocument = Nothing
    ' 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.
    Dim tempUri As New Uri(_xpsDocumentPath, UriKind.RelativeOrAbsolute)
    Dim parserContext As New ParserContext()
    parserContext.BaseUri = PackUriHelper.Create(tempUri)
    ' Retrieve the fixed document.
    Dim fixedDocPart As PackagePart = _xpsPackage.GetPart(fixedDocUri)
    If fixedDocPart IsNot Nothing Then
        Dim fixedObject As Object = XamlReader.Load(fixedDocPart.GetStream(), parserContext)
        If fixedObject IsNot Nothing Then
            fixedDocument = TryCast(fixedObject, FixedDocument)
        End If
    End If
    Return fixedDocument
End Function ' end:GetFixedDocument()
    	注解
              packageUri 不能指定为 null 或为空。
如果 partUri 为 null,则返回的包 URI 指向包。
              fragment 不能为空字符串,但可以指定为 null。  如果未指定为 null,则 fragment 字符串必须以“#”字符开头。  有关引用语法 fragment 的详细信息,请参阅 RFC 3986 的第 3.5 节“片段”。
下表说明了 方法的示例用例 Create 。
packageUri | 
partUri | 
fragment | 
返回的包 URI | 
|---|---|---|---|
http://www.proseware.com/mypackage.pkg | 
/page1.xaml | #intro | pack://http:,www.proseware.com,mypackage.pkg/page1.xaml#intro | 
http://www.proseware.com/mypackage.pkg | 
/page2.xaml | null | pack://http:,www.proseware.com,mypackage.pkg/page2.xaml | 
http://www.proseware.com/mypackage.pkg | 
/a/page4.xaml | null | pack://http:,www.proseware.com,mypackage.pkg/a/page4.xaml | 
http://www.proseware.com/mypackage.pkg | 
/%41/%61.xml | null | pack://http:,,www.proseware.com,mypackage.pkg/A/a.xml | 
http://www.proseware.com/mypackage.pkg | 
/%25XY.xml | null | pack://http:,www.proseware.com,mypackage.pkg/%25XY.xml | 
http://www.proseware.com/mypackage.pkg | 
/a/page5.xaml | #summary | pack://http:,www.proseware.com,mypackage.pkg/a/page5.xaml#summary | 
http://www.proseware.com/packages.aspx?pkg04 | 
/page1.xaml | #intro | pack://http:,www.proseware.com,packages.aspx%3fpkg04/page1.xaml#intro | 
http://www.proseware.com/mypackage.pkg | 
null | null | pack://http:,www.proseware.com,mypackage.pkg | 
ftp://ftp.proseware.com/packages/mypackage1.abc | 
/a/mydoc.xaml | null | pack://ftp:,,ftp.proseware.com,packages,mypackage1.abc/a/mydoc.xaml | 
file:///d:/packages/mypackage2.pkg | 
/a/bar.xaml | #xref | pack://file:,,,d:,packages,mypackage2.pkg/a/bar.xaml#xref | 
编写包 URI 是一个多步骤过程。  例如,形成 pack URI 的一个步骤是将 的正斜杠 (/) 字符 packageUri 替换为逗号 (,) 。
有关字符串转换以及如何形成包 URI 的详细信息,请参阅规范和 许可证下载中可供下载的开放打包约定规范中的附录 A.4“字符串转换示例”和附录 B.3“撰写包 URI”。