使用C#--Windows 8应用商店打开PDF
我希望能够在用户单击按钮时使用本机Windows Reader应用程序打开PDF。到目前为止,我能够使用以下代码成功地打开以(.PNG)扩展名结尾的文件。但是,当我让链接打开(.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
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文档
- 点击属性
- 将构建操作从无更改为内容