PackUriHelper.Create 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立一個新的包 URI。
多載
| 名稱 | Description |
|---|---|
| Create(Uri) |
建立一個新的包 URI,指向一個套件。 |
| Create(Uri, Uri) |
建立一個包 URI,給定一個 Package URI 和封包中某個零件的 URI。 |
| Create(Uri, Uri, String) |
建立一個包 URI,給定一個 Package 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 | 零 | 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 |
/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 |
零 | 零 | 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 | #xref | pack://file:,,,d:,packages,mypackage2.pkg/a/bar.xaml#xref |
撰寫包 URI 是一個多步驟的過程。 例如,形成包 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
參數
傳回
該包 URI Package 由給定 packageUri的參考 。
例外狀況
packageUri 是 null。
packageUri 並非絕對的上呼吸道。
範例
以下範例說明如何使用此 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 是一個多步驟的過程。 例如,形成包 URI 的一個步驟是將 中的 packageUri 斜線(/)字元替換成逗號(,)。
欲了解更多關於字串轉換及包 URI 如何形成的資訊,請參閱開放包裝公約規範中的附錄 A.4「字串轉換範例」及附錄 B.3「組合包 URI」,可於 規範與授權下載處下載。
另請參閱
適用於
Create(Uri, Uri)
建立一個包 URI,給定一個 Package 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
套件中的 URI PackagePart 。
傳回
給定 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 不得指定為空或空。
若 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 |
零 | 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 是一個多步驟的過程。 例如,形成包 URI 的一個步驟是將 中的 packageUri 斜線(/)字元替換成逗號(,)。
欲了解更多關於字串轉換及包 URI 如何形成的資訊,請參閱開放包裝公約規範中的附錄 A.4「字串轉換範例」及附錄 B.3「組合包 URI」,可於 規範與授權下載處下載。
另請參閱
適用於
Create(Uri, Uri, String)
建立一個包 URI,給定一個 Package 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
套件中的 URI PackagePart 。
- 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 | 零 | 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 |
/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 |
零 | 零 | 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 | #xref | pack://file:,,,d:,packages,mypackage2.pkg/a/bar.xaml#xref |
撰寫包 URI 是一個多步驟的過程。 例如,形成包 URI 的一個步驟是將 中的 packageUri 斜線(/)字元替換成逗號(,)。
欲了解更多關於字串轉換及包 URI 如何形成的資訊,請參閱開放包裝公約規範中的附錄 A.4「字串轉換範例」及附錄 B.3「組合包 URI」,可於 規範與授權下載處下載。