2013-05-15 53 views
2

我希望在用戶單擊按鈕時能夠使用本機Windows Reader應用程序打開PDF。到目前爲止,我可以使用以下代碼成功打開以(.PNG)擴展名結尾的文件。但是,當我讓鏈接打開(.PDF)文件時,出現以下錯誤。使用C#打開PDF - Windows 8 Store應用程序

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 
     } 
    } 
} 
+0

在什麼地方發生錯誤?你檢查過這個文件是否真的存在? –

+0

錯誤發生在var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);我通過添加 - >現有項目將pdf添加到文件夾。我可以通過在實際文件夾中雙擊它來打開PDF中的PDF – Dadles

回答

6

當您添加項目的PDF文檔,你必須改變它的建設行動。

  • 右鍵單擊PDF文檔。

  • 點擊屬性。

  • 變化生成操作內容

+0

工作表示感謝! – Dadles

+0

不客氣:) – Xyroid

相關問題