簡體   English   中英

如何在 HoloLens UWP 的關聯應用中啟動 PDF 文件?

[英]How to launch PDF file in associated app in HoloLens UWP?

我正在嘗試在 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
        }

獲取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.

有人可以幫我解決這個問題嗎? 我只想用與文件類型關聯的相應應用程序打開一些文件。

  1. 驗證該文件是否包含在您的項目中,並且 Build Action 設置為“Content”。

  2. 切換到通過StorageFile.GetFileFromApplicationUriAsync調用檢索IStorageFile引用。

以下代碼在常規 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM