PackageStore.AddPackage(Uri, Package) 메서드

정의

저장소에 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

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

package
Package

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

예외

package이(가) null인 경우

packageUri가 잘못된 패키지 URI인 경우

지정된 packageUri의 패키지가 이미 저장소에 있는 경우

예제

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

if (rmi.CryptoProvider.CanDecrypt == true)
    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()

설명

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

경우는 packageUri 에 대 한 PackagePartPackWebRequest 일치 Uri 하는 호출에서, 패키지에 PackageStore 정의 된 요청 된 부분에 액세스 하는 데 사용 됩니다.

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

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

적용 대상

추가 정보