Udostępnij przez


PackUriHelper.Create Metoda

Definicja

Tworzy nowy identyfikator URI pakietu.

Przeciążenia

Create(Uri)

Tworzy nowy identyfikator URI pakietu wskazujący pakiet.

Create(Uri, Uri)

Tworzy identyfikator URI pakietu przy użyciu identyfikatora Package URI i identyfikatora URI części pakietu.

Create(Uri, Uri, String)

Tworzy identyfikator URI pakietu przy użyciu identyfikatora Package URI, identyfikatora URI części w pakiecie i fragmentu "#", który ma być dołączany.

Uwagi

W poniższej Create tabeli przedstawiono przykładowe przypadki dla metody .

packageUri partUri fragment Zwracany identyfikator URI pakietu
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

Tworzenie identyfikatora URI pakietu jest procesem wieloetapowym. Na przykład jeden krok podczas tworzenia identyfikatora URI pakietu polega na zastąpieniu ukośnika (/) znaków packageUri ukośnika (/) przecinków (,).

Aby uzyskać więcej informacji na temat konwersji ciągów i sposobu tworzenia identyfikatorów URI pakietów, zobacz Dodatek A.4 "Przykłady konwersji ciągów" i dodatek B.3 "Tworzenie identyfikatora URI pakietu" w specyfikacji Open Packaging Conventions dostępne do pobrania w specyfikacji i pobieraniu licencji.

Create(Uri)

Źródło:
PackUriHelper.PackUriScheme.cs
Źródło:
PackUriHelper.PackUriScheme.cs
Źródło:
PackUriHelper.PackUriScheme.cs

Tworzy nowy identyfikator URI pakietu wskazujący pakiet.

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

Parametry

packageUri
Uri

Identyfikator URI odwołania Package.

Zwraca

Uri

Identyfikator URI pakietu dla Package elementu, do których odwołuje się dany packageUrielement .

Wyjątki

packageUri to null.

packageUri nie jest bezwzględnym identyfikatorem URI.

Przykłady

W poniższym przykładzie pokazano, jak użyć Create metody do zdefiniowania identyfikatora URI pakietu, który odwołuje się do pakietu.

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

Uwagi

packageUri nie może być określony jako null lub pusty.

W poniższej tabeli przedstawiono przykładowe przypadki dla programu Create.

packageUri Identyfikator URI zwróconego pakietu
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

Tworzenie identyfikatora URI pakietu jest procesem wieloetapowym. Na przykład jednym krokiem tworzenia identyfikatora URI pakietu jest zastąpienie ukośnika (/) znaków packageUri ukośnika (/) przecinków (,).

Aby uzyskać więcej informacji na temat konwersji ciągów i sposobu tworzenia identyfikatorów URI pakietów, zobacz Dodatek A.4 "Przykłady konwersji ciągów" i dodatek B.3 "Tworzenie identyfikatora URI pakietu" w specyfikacji Open Packaging Conventions dostępne do pobrania w Specyfikacje i Pliki do pobrania licencji.

Zobacz też

Dotyczy

Create(Uri, Uri)

Źródło:
PackUriHelper.PackUriScheme.cs
Źródło:
PackUriHelper.PackUriScheme.cs
Źródło:
PackUriHelper.PackUriScheme.cs

Tworzy identyfikator URI pakietu przy użyciu identyfikatora Package URI i identyfikatora URI części pakietu.

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

Parametry

packageUri
Uri

Identyfikator URI obiektu Package.

partUri
Uri

Identyfikator URI elementu PackagePart w pakiecie.

Zwraca

Uri

Identyfikator URI pakietu danego PackagePartelementu .

Wyjątki

packageUri to null.

packageUri nie jest bezwzględnym identyfikatorem URI.

-lub-

partUri nie jest prawidłową składnią identyfikatora URI części.

Przykłady

W poniższym przykładzie pokazano, jak użyć Create(Uri) metody do zdefiniowania identyfikatora URI pakietu, który odwołuje się do pakietu.

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

Uwagi

packageUri nie może być określona jako null lub pusta.

Jeśli partUri ma nullwartość , zwrócony identyfikator URI pakietu wskazuje pakiet.

W poniższej tabeli przedstawiono przykładowe przypadki dla Create metody .

packageUri partUri Identyfikator URI zwróconego pakietu
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

Tworzenie identyfikatora URI pakietu jest procesem wieloetapowym. Na przykład jednym krokiem tworzenia identyfikatora URI pakietu jest zastąpienie ukośnika (/) znaków packageUri ukośnika (/) przecinków (,).

Aby uzyskać więcej informacji na temat konwersji ciągów i sposobu tworzenia identyfikatorów URI pakietów, zobacz Dodatek A.4 "Przykłady konwersji ciągów" i dodatek B.3 "Tworzenie identyfikatora URI pakietu" w specyfikacji Open Packaging Conventions dostępne do pobrania w Specyfikacje i Pliki do pobrania licencji.

Zobacz też

Dotyczy

Create(Uri, Uri, String)

Źródło:
PackUriHelper.PackUriScheme.cs
Źródło:
PackUriHelper.PackUriScheme.cs
Źródło:
PackUriHelper.PackUriScheme.cs

Tworzy identyfikator URI pakietu z identyfikatorem Package URI, identyfikatorem URI części w pakiecie i fragmentem "#" do dołączenia.

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

Parametry

packageUri
Uri

Identyfikator URI obiektu Package.

partUri
Uri

Identyfikator URI elementu PackagePart w pakiecie.

fragment
String

Odwołanie "#" identyfikujące element w części pakietu.

Zwraca

Uri

Identyfikator URI pakietu identyfikujący określony pakiet, część pakietu i fragment.

Wyjątki

packageUri to null.

packageUri nie jest bezwzględnym identyfikatorem URI.

-lub-

partUri nie jest prawidłową składnią identyfikatora URI części.

-lub-

fragment jest pusty lub zaczyna się od ciągu "#".

Przykłady

W poniższym przykładzie pokazano, jak użyć Create(Uri) metody do zdefiniowania identyfikatora URI pakietu, który odwołuje się do pakietu.

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

Uwagi

packageUri nie może być określony jako null lub pusty.

Jeśli partUri ma nullwartość , zwrócony identyfikator URI pakietu wskazuje pakiet.

fragment nie może być pustym ciągiem, ale można go określić jako null. Jeśli nie zostanie określony jako null, fragment ciąg musi zaczynać się od znaku "#". Aby uzyskać więcej informacji na temat składni fragment odwołań, zobacz sekcję 3.5 "Fragment" RFC 3986.

W poniższej tabeli przedstawiono przykładowe przypadki dla Create metody .

packageUri partUri fragment Identyfikator URI zwróconego pakietu
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

Tworzenie identyfikatora URI pakietu jest procesem wieloetapowym. Na przykład jeden krok podczas tworzenia identyfikatora URI pakietu polega na zastąpieniu ukośnika (/) znaków packageUri ukośnika (/) przecinków (,).

Aby uzyskać więcej informacji na temat konwersji ciągów i sposobu tworzenia identyfikatorów URI pakietów, zobacz Dodatek A.4 "Przykłady konwersji ciągów" i dodatek B.3 "Tworzenie identyfikatora URI pakietu" w specyfikacji Open Packaging Conventions dostępne do pobrania w specyfikacji i pobieraniu licencji.

Zobacz też

Dotyczy