[英]How to launch PDF file in associated app in HoloLens UWP?
I'm trying to open a PDF file, packaged inside app folder ("Assets"), in HoloLens (C#) app.我正在尝试在 HoloLens (C#) 应用程序中打开一个打包在应用程序文件夹(“资产”)中的 PDF 文件。
string imageFile = @"Assets\test.jpg";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
Debug.WriteLine("Opening file in path :" + file.Path);
if (file != null)
{
Debug.WriteLine("File found\nLaunching file...");
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
var success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{
Debug.WriteLine("File launched successfully");
// File launched
}
else
{
Debug.WriteLine("File launch failed");
// File launch failed
}
}
else
{
Debug.WriteLine("Could not find file");
// Could not find file
}
Getting Access is Denied
error.获取
Access is Denied
错误。
Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.ni.dll
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SchneiderDemoLibrary.HoloHelper.<DefaultLaunch>d__3.MoveNext() Exception caught.
Can someone help me to solve this issue?有人可以帮我解决这个问题吗? I simply want to open some file with the corresponding app associated with the file type.
我只想用与文件类型关联的相应应用程序打开一些文件。
Verify that the file is included in your project, and that the Build Action is set to "Content".验证该文件是否包含在您的项目中,并且 Build Action 设置为“Content”。
Switch to retrieving the IStorageFile
reference via the StorageFile.GetFileFromApplicationUriAsync
call.切换到通过
StorageFile.GetFileFromApplicationUriAsync
调用检索IStorageFile
引用。
The following code is working for me in a regular UWP application:以下代码在常规 UWP 应用程序中对我有用:
private async void OpenPdfButton_Click(object sender, RoutedEventArgs e)
{
var file = await StorageFile.GetFileFromApplicationUriAsync
(
new Uri("ms-appx:///Content/output.pdf")
);
await Launcher.LaunchFileAsync(file);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.