1

我正在尝试在 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.

有人可以帮我解决这个问题吗?我只是想用与文件类型关联的相应应用程序打开一些文件。

4

1 回答 1

1
  1. 验证文件是否包含在您的项目中,并且构建操作设置为“内容”。

  2. 切换到通过调用检索IStorageFile引用。StorageFile.GetFileFromApplicationUriAsync

以下代码在常规 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);
}
于 2017-01-27T07:37:21.937 回答