2017-01-16 38 views
1

我試圖在HoloLens(C#)應用程序中打開一個打包在應用程序文件夾(「資產」)中的PDF文件。如何在HoloLens UWP的相關應用中啓動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. 

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

+0

您是否嘗試過'的Process.Start(pdfFile)'? –

+0

@JamesHughes通用Windows應用程序中沒有'Process.Start'。 – BrainSlugs83

+0

得到它的工作。我試圖從Unity 3D運行此代碼。現在我已經動態創建了2D窗口,並在2D窗口加載時觸發了上述代碼。 –

回答

1
  1. 驗證文件是否包含在您的項目中,並且生成操作設置爲「內容」。

  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); 
} 
相關問題