当前位置: 首页>>代码示例>>C#>>正文


C# PackageStore.GetPackage方法代码示例

本文整理汇总了C#中System.IO.Packaging.PackageStore.GetPackage方法的典型用法代码示例。如果您正苦于以下问题:C# PackageStore.GetPackage方法的具体用法?C# PackageStore.GetPackage怎么用?C# PackageStore.GetPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。


在下文中一共展示了PackageStore.GetPackage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenDocument

// --------------------------- OpenDocument ---------------------------
/// <summary>
///   Loads and displays a given XPS document file.</summary>
/// <param name="filename">
///   The path and file name of the XPS
///   document to load and display.</param>
/// <returns>
///   true if the document loads successfully; otherwise false.</returns>
public bool OpenDocument(string xpsFile)
{
    // Check to see if the document is encrypted.
    // If encrypted, use OpenEncryptedDocument().
    if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(xpsFile))
        return OpenEncryptedDocument(xpsFile);

    // Document is not encrypted, open normally.
    ShowStatus("Opening '" + Filename(xpsFile) + "'");

    _packageUri = new Uri(xpsFile, UriKind.Absolute);
    try
    {
        _xpsDocument = new XpsDocument(xpsFile, FileAccess.Read);
    }
    catch (System.IO.FileFormatException ex)
    {
        MessageBox.Show(xpsFile + "\n\nThe file " +
            "is not a valid XPS document.\n\n" +
            "Exception: " + ex.Message + "\n\n" +
            ex.GetType().ToString() + "\n\n" + ex.StackTrace,
            "Invalid File Format",
            MessageBoxButton.OK, MessageBoxImage.Error);
        return false;
    }

    // Get the document's PackageStore into which
    // new user annotations will be added and saved.
    _xpsPackage = PackageStore.GetPackage(_packageUri);
    if ((_xpsPackage == null) || (_xpsDocument == null))
    {
        MessageBox.Show("Unable to get Package from file.");
        return false;
    }

    // Get the FixedDocumentSequence from the open document.
    FixedDocumentSequence fds = _xpsDocument.GetFixedDocumentSequence();
    if (fds == null)
    {
        MessageBox.Show(xpsFile + "\n\nThe document package within " +
            "the specified file does not contain a " +
            "FixedDocumentSequence.", "Package Error");
        return false;
    }

    // Load the FixedDocumentSequence to the DocumentViewer control.
    DocViewer.Document = fds;

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

    // Give the DocumentViewer focus.
    docViewer.Focus();

    this.Title = "RightsManagedPackageViewer SDK Sample - " +
                 Filename(xpsFile);
    return true;
}// end:OpenDocument()
开发者ID:.NET开发者,项目名称:System.IO.Packaging,代码行数:69,代码来源:PackageStore.GetPackage


注:本文中的System.IO.Packaging.PackageStore.GetPackage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。