使用C#--Windows 8应用商店打开PDF

使用C#--Windows 8应用商店打开PDF,c#,pdf,windows-8,winrt-xaml,C#,Pdf,Windows 8,Winrt Xaml,我希望能够在用户单击按钮时使用本机Windows Reader应用程序打开PDF。到目前为止,我能够使用以下代码成功地打开以(.PNG)扩展名结尾的文件。但是,当我让链接打开(.PDF)文件时,我得到了以下错误 The system cannot find the file specified. (Exception from HRESULT: 0x80070002) 文件目标是正确的 这是我的密码: private async void btnLoad_Click(object sende

我希望能够在用户单击按钮时使用本机Windows Reader应用程序打开PDF。到目前为止,我能够使用以下代码成功地打开以(.PNG)扩展名结尾的文件。但是,当我让链接打开(.PDF)文件时,我得到了以下错误

The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
文件目标是正确的

这是我的密码:

 private async void btnLoad_Click(object sender, RoutedEventArgs e)
    {
        // Path to the file in the app package to launch
        string imageFile = @"Data\Healthcare-Flyer.pdf";

        var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);

        if (file != null)
        {
            // Set the option to show the picker
            var options = new Windows.System.LauncherOptions();
            options.DisplayApplicationPicker = true;

            // Launch the retrieved file
            bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
            if (success)
            {
                // File launched
            }
            else
            {
                // File launch failed
            }
        }
        else
        {
            // Could not find file
        }
    }
}

在项目中添加PDF文档时,必须更改其生成操作

  • 右键单击PDF文档

  • 点击属性

  • 构建操作更改为内容


错误发生在哪里?是否检查文件是否确实存在?错误发生在var file=wait Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile)上;我通过“添加->现有项目”将pdf添加到文件夹中。我可以通过双击实际文件夹中的PDF在reader中打开它