PackUriHelper.Create Metodo

Definizione

Crea un nuovo URI di tipo pack.

Overload

Create(Uri)

Crea un nuovo URI di tipo pack che punta a un pacchetto.

Create(Uri, Uri)

Crea un URI di tipo pack, dato un URI di Package e l'URI di una parte nel pacchetto.

Create(Uri, Uri, String)

Crea un URI di tipo pack dato un URI di Package, l'URI di una parte nel pacchetto e un frammento "#" da accodare.

Commenti

La tabella seguente illustra i casi di esempio per il Create metodo .

packageUri partUri fragment URI del pacchetto restituito
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

La composizione di un URI del pacchetto è un processo in più passaggi. Ad esempio, un passaggio nella forma di un URI del pacchetto consiste nel sostituire i caratteri della barra (/) con packageUri virgole (,).

Per altre informazioni sulla conversione delle stringhe e sul formato degli URI dei pacchetti, vedere Appendice A.4 "Esempi di conversione stringa" e Appendice B.3 "Composizione di un URI pack" nella specifica Open Packaging Conventions disponibile per il download in Specifiche e download delle licenze.

Create(Uri)

Crea un nuovo URI di tipo pack che punta a un pacchetto.

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

Parametri

packageUri
Uri

URI dell'oggetto Package a cui si fa riferimento.

Restituisce

Uri

URI di tipo pack per l'oggetto Package a cui fa riferimento l'oggetto packageUri specificato.

Eccezioni

packageUri è null.

packageUri non è un URI assoluto.

Esempio

Nell'esempio seguente viene illustrato come usare il Create metodo per definire un URI del pacchetto che fa riferimento a un pacchetto.

// ------------------------ 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()

Commenti

packageUri potrebbe non essere specificato come null o vuoto.

La tabella seguente illustra i casi di esempio per Create.

packageUri URI del pacchetto restituito
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

La composizione di un URI del pacchetto è un processo in più passaggi. Ad esempio, un passaggio nella forma di un URI del pacchetto consiste nel sostituire i caratteri della barra (/) con packageUri virgole (,).

Per altre informazioni sulla conversione delle stringhe e sul formato degli URI dei pacchetti, vedere Appendice A.4 "Esempi di conversione stringa" e Appendice B.3 "Composizione di un URI pack" nella specifica Open Packaging Conventions disponibile per il download in Specifiche e download delle licenze.

Vedi anche

Si applica a

Create(Uri, Uri)

Crea un URI di tipo pack, dato un URI di Package e l'URI di una parte nel pacchetto.

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

Parametri

packageUri
Uri

URI di Package.

partUri
Uri

URI dell'oggetto PackagePart nel pacchetto.

Restituisce

Uri

URI di tipo pack dell'oggetto PackagePart specificato.

Eccezioni

packageUri è null.

packageUri non è un URI assoluto.

-oppure- partUri non è una sintassi URI valida per la parte.

Esempio

Nell'esempio seguente viene illustrato come usare il Create(Uri) metodo per definire un URI del pacchetto che fa riferimento a un pacchetto.

// ------------------------ 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()

Commenti

packageUri potrebbe non essere specificato come null o vuoto.

Se partUri è null, l'URI del pacchetto restituito punta al pacchetto.

La tabella seguente illustra i casi di esempio per il Create metodo .

packageUri partUri URI del pacchetto restituito
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

La composizione di un URI del pacchetto è un processo in più passaggi. Ad esempio, un passaggio nella forma di un URI del pacchetto consiste nel sostituire i caratteri della barra (/) con packageUri virgole (,).

Per altre informazioni sulla conversione delle stringhe e sul formato degli URI dei pacchetti, vedere Appendice A.4 "Esempi di conversione stringa" e Appendice B.3 "Composizione di un URI pack" nella specifica Open Packaging Conventions disponibile per il download in Specifiche e download delle licenze.

Vedi anche

Si applica a

Create(Uri, Uri, String)

Crea un URI di tipo pack dato un URI di Package, l'URI di una parte nel pacchetto e un frammento "#" da accodare.

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

Parametri

packageUri
Uri

URI di Package.

partUri
Uri

URI dell'oggetto PackagePart nel pacchetto.

fragment
String

Riferimento "#" che identifica un elemento all'interno della parte del pacchetto.

Restituisce

Uri

URI di tipo pack che identifica il pacchetto, la parte del pacchetto e il frammento specificati.

Eccezioni

packageUri è null.

packageUri non è un URI assoluto.

-oppure- partUri non è una sintassi URI valida per la parte.

-oppure- fragment è vuoto o inizia con "#".

Esempio

Nell'esempio seguente viene illustrato come usare il Create(Uri) metodo per definire un URI del pacchetto che fa riferimento a un pacchetto.

// ------------------------ 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()

Commenti

packageUri potrebbe non essere specificato come null o vuoto.

Se partUri è null, l'URI del pacchetto restituito punta al pacchetto.

fragment non può essere una stringa vuota, ma può essere specificata come null. Se non specificato come null, la fragment stringa deve iniziare con un carattere '#'. Per altre informazioni sulla sintassi dei fragment riferimenti, vedere Sezione 3.5 "Frammento" di RFC 3986.

La tabella seguente illustra i casi di esempio per il Create metodo .

packageUri partUri fragment URI del pacchetto restituito
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

La composizione di un URI del pacchetto è un processo in più passaggi. Ad esempio, un passaggio nella forma di un URI del pacchetto consiste nel sostituire i caratteri della barra (/) con packageUri virgole (,).

Per altre informazioni sulla conversione delle stringhe e sul formato degli URI dei pacchetti, vedere Appendice A.4 "Esempi di conversione stringa" e Appendice B.3 "Composizione di un URI pack" nella specifica Open Packaging Conventions disponibile per il download in Specifiche e download delle licenze.

Vedi anche

Si applica a