PackageStore.AddPackage(Uri, Package) 메서드

정의

저장소에 a Package 를 추가합니다.

public:
 static void AddPackage(Uri ^ uri, System::IO::Packaging::Package ^ package);
public static void AddPackage(Uri uri, System.IO.Packaging.Package package);
static member AddPackage : Uri * System.IO.Packaging.Package -> unit
Public Shared Sub AddPackage (uri As Uri, package As Package)

매개 변수

uri
Uri

에서 비교할 키 URI package 입니다 PackWebRequest.

package
Package

저장소에 추가할 패키지입니다.

예외

packagenull입니다.

uri 가 잘못된 패키지 URI입니다.

지정된 uri 패키지가 이미 저장소에 있습니다.

예제

다음 예제에서는 메서드를 사용하는 AddPackage 방법을 보여줍니다.

if (rmi.CryptoProvider.CanDecrypt)
    ShowStatus("   Decryption granted.");
else
    ShowStatus("   CANNOT DECRYPT!");

ShowStatus("   Getting the Package from\n" +
           "      the EncryptedPackage.");
_xpsPackage = ePackage.GetPackage();
if (_xpsPackage == null)
{
    MessageBox.Show("Unable to get Package.");
    return false;
}

// Set a PackageStore Uri reference for the encrypted stream.
// ("sdk://packLocation" is a pseudo URI used by
//  PackUriHelper.Create to define the parserContext.BaseURI
//  that XamlReader uses to access the encrypted data stream.)
Uri packageUri = new Uri(@"sdk://packLocation", UriKind.Absolute);
// Add the URI package
PackageStore.AddPackage(packageUri, _xpsPackage);
// Determine the starting part for the package.
PackagePart startingPart = GetPackageStartingPart(_xpsPackage);

// Set the DocViewer.Document property.
ShowStatus("   Opening in DocumentViewer.");
ParserContext parserContext = new ParserContext();
parserContext.BaseUri = PackUriHelper.Create(
                            packageUri, startingPart.Uri);
parserContext.XamlTypeMapper = XamlTypeMapper.DefaultMapper;
DocViewer.Document = XamlReader.Load(
    startingPart.GetStream(), parserContext)
        as IDocumentPaginatorSource;

// Enable document menu controls.
menuFileClose.IsEnabled = true;
menuFilePrint.IsEnabled = true;
menuViewIncreaseZoom.IsEnabled = true;
menuViewDecreaseZoom.IsEnabled = true;

// Give the DocumentViewer focus.
DocViewer.Focus();
If rmi.CryptoProvider.CanDecrypt = True Then
    ShowStatus("   Decryption granted.")
Else
    ShowStatus("   CANNOT DECRYPT!")
End If

ShowStatus("   Getting the Package from" & vbLf & "      the EncryptedPackage.")
_xpsPackage = ePackage.GetPackage()
If _xpsPackage Is Nothing Then
    MessageBox.Show("Unable to get Package.")
    Return False
End If

' Set a PackageStore Uri reference for the encrypted stream.
' ("sdk://packLocation" is a pseudo URI used by
'  PackUriHelper.Create to define the parserContext.BaseURI
'  that XamlReader uses to access the encrypted data stream.)
Dim packageUri As New Uri("sdk://packLocation", UriKind.Absolute)
' Add the URI package
PackageStore.AddPackage(packageUri, _xpsPackage)
' Determine the starting part for the package.
Dim startingPart As PackagePart = GetPackageStartingPart(_xpsPackage)

' Set the DocViewer.Document property.
ShowStatus("   Opening in DocumentViewer.")
Dim parserContext As New ParserContext()
parserContext.BaseUri = PackUriHelper.Create(packageUri, startingPart.Uri)
parserContext.XamlTypeMapper = XamlTypeMapper.DefaultMapper
DocViewerProperty.Document = TryCast(XamlReader.Load(startingPart.GetStream(), parserContext), IDocumentPaginatorSource)

' Enable document menu controls.
menuFileClose.IsEnabled = True
menuFilePrint.IsEnabled = True
menuViewIncreaseZoom.IsEnabled = True
menuViewDecreaseZoom.IsEnabled = True

' Give the DocumentViewer focus.
DocViewerProperty.Focus()

설명

uri 는 호출 PackWebRequest할 때 비교되는 패키지의 키 URI를 정의합니다.

호출에서 uriUriPackagePartPackWebRequest 의 패키지와 일치하는 경우 정의된 패키지 PackageStore 는 요청된 부분에 액세스하는 데 사용됩니다.

호출에서 uri 의 패키지와 일치하지 UriPackagePartPackWebRequest 않으면 지정된 URI가 있는 패키지가 열려 요청된 파트에 액세스합니다.

보안 참고 사항 이 메서드는 EnvironmentPermission 모든 사용자 지정 Package (비ZipPackage) 형식을 요구합니다.

적용 대상

추가 정보