2013-04-13 4 views
4

Windows8 기본 판독기에서 열어야하는 버튼을 클릭하여 winRT 앱 (메트로 스타일 앱)에서 pdf 파일을 열려고합니다. 그것은 파일을 .png를 위해 일버튼을 클릭하면 PDF 파일이 열립니다

async void DefaultLaunch_click() 
{ 
    // Path to the file in the app package to launch 
    string imageFile = @"images\ret.png"; 

// Get the image file from the package's image directory 
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile); 



if (file != null) 
{ 
// Set the recommended app 
    var options = new Windows.System.LauncherOptions(); 
    options.PreferredApplicationPackageFamilyName = “Contoso.FileApp_8wknc82po1e”; 
    options.PreferredApplicationDisplayName = “Contoso File App”; 




    // Launch the retrieved file pass in the recommended app 
    // in case the user has no apps installed to handle the file 
    bool success = await Windows.System.Launcher.LaunchFileAsync(file, options); 
    if (success) 
    { 
    // File launched 
    } 
    else 
    { 
    // File launch failed 
    } 
    } 
    else 
    { 
     // Could not find file 
    } 
    } 

하지만 난 (이미지 폴더에 포함 후) 내가 M.pdf로 1.png을 대체 .pdf 파일에 대해 원하는 :이 코드, 버튼 클릭 메소드 이름이 DefaultLaunch_click()입니다 시도 와, 포함 리소스에 M.pdf의 빌드 내용을 설정 프로그램을 실행하지만 내가 콘텐츠를 PDF 파일 빌드 작업을 설정하고 출력 디렉터리에 항상 복사 한 후

**The system cannot find the file specified. (Exception from HRESULT: 0x80070002)** 

답변

1

이 코드는 나를 위해 작동 오류를 보여 주었다.

private async void Button_Click(object sender, RoutedEventArgs e) 
    { 
     string imageFile = @"images\somepdffile.pdf"; 

     // Get the image file from the package's image directory 
     var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile); 
     if (file != null) 
     { 
      bool success = await Windows.System.Launcher.LaunchFileAsync(file, options); 
      if (success) 
      { 
       // File launched 
      } 
      else 
      { 
       // File launch failed 
      } 
     } 
     else 
     { 
      // Could not find file 
     } 
    } 
+1

네, 그것도 잘 작동했습니다 .--). Thankyouu ... :) –

+0

여기 좀 봐 주시겠습니까? http://stackoverflow.com/questions/22011326/open-pdf-file-in-emulator – user2056563

관련 문제