当用户单击按钮时,我希望能够使用本机 Windows 阅读器应用程序打开 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
}
}
}