PackUriHelper.Create Metodo

Definizione

Crea un nuovo URI pack.

Overload

Nome Descrizione
Create(Uri)

Crea un nuovo URI pack che punta a un pacchetto.

Create(Uri, Uri)

Crea un URI di tipo pack in base a un Package URI e all'URI di una parte nel pacchetto.

Create(Uri, Uri, String)

Crea un URI di tipo pack in base a un Package URI, all'URI di una parte del pacchetto e a un frammento "#" da accodare.

Commenti

Nella tabella seguente vengono illustrati i casi di esempio per il Create metodo .

packageUri partUri fragment URI 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 di tipo pack è un processo in più passaggi. Ad esempio, un passaggio per formare un URI di tipo pack consiste nel sostituire i caratteri barra (/) di packageUri con virgole (,).

Per altre informazioni sulla conversione di stringhe e sul formato degli URI di pacchetto, vedere Appendice A.4 "Esempi di conversione di stringhe" 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 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 a cui si fa Packageriferimento.

Valori restituiti

Uri

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

Eccezioni

packageUri è null.

packageUri non è un URI assoluto.

Esempio

Nell'esempio seguente viene illustrato come utilizzare il Create metodo per definire un URI pack 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 non può essere specificato come null o vuoto.

Nella tabella seguente vengono illustrati i casi di esempio per Create.

packageUri URI 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 di tipo pack è un processo in più passaggi. Ad esempio, un passaggio per formare un URI di tipo pack consiste nel sostituire i caratteri barra (/) di packageUri con virgole (,).

Per altre informazioni sulla conversione di stringhe e sul formato degli URI di pacchetto, vedere Appendice A.4 "Esempi di conversione di stringhe" 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 in base a un Package URI e all'URI di una parte nel pacchetto.

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 dell'oggetto Package.

partUri
Uri

URI dell'oggetto PackagePart nel pacchetto.

Valori restituiti

Uri

URI pack dell'oggetto specificato PackagePart.

Eccezioni

packageUri è null.

packageUri non è un URI assoluto.

oppure

partUri non è una sintassi URI di parte valida.

Esempio

Nell'esempio seguente viene illustrato come utilizzare il Create(Uri) metodo per definire un URI pack 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 non può essere specificato come null o vuoto.

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

Nella tabella seguente vengono illustrati i casi di esempio per il Create metodo .

packageUri partUri URI 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 di tipo pack è un processo in più passaggi. Ad esempio, un passaggio per formare un URI di tipo pack consiste nel sostituire i caratteri barra (/) di packageUri con virgole (,).

Per altre informazioni sulla conversione di stringhe e sul formato degli URI di pacchetto, vedere Appendice A.4 "Esempi di conversione di stringhe" 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 in base a un Package URI, all'URI di una parte del pacchetto e a 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);
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 dell'oggetto Package.

partUri
Uri

URI dell'oggetto PackagePart nel pacchetto.

fragment
String

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

Valori restituiti

Uri

URI 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 di parte valida.

oppure

fragment è vuoto o inizia con "#".

Esempio

Nell'esempio seguente viene illustrato come utilizzare il Create(Uri) metodo per definire un URI pack 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 non può 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 la sezione 3.5 "Fragment" di RFC 3986.

Nella tabella seguente vengono illustrati i casi di esempio per il Create metodo .

packageUri partUri fragment URI 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 di tipo pack è un processo in più passaggi. Ad esempio, un passaggio per formare un URI di tipo pack consiste nel sostituire i caratteri barra (/) di packageUri con virgole (,).

Per altre informazioni sulla conversione di stringhe e sul formato degli URI di pacchetto, vedere Appendice A.4 "Esempi di conversione di stringhe" 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