0

I am new to UWP.

I am copying the LaunchFileAsync with DisplayApplicationPicker from the documentation to my project:

        string imageFile = @"test.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  ====> GETTING TO HERE
            }
        }
        else
        {
            // Could not find file
        }

The return value is false.

Why?

BTW, calling LaunchFileAsync(file) (without the options argument) - opens the pdf file in Edge (my default PDF app).

RK Coder
  • 398
  • 2
  • 14

1 Answers1

0

LaunchFileAsync fails when DisplayApplicationPicker=true

I have tested above code, but we could not reproduce this issue. Please check if your pdf is build action is Content and tested the app in the latest OS version(1909).

BTW, calling LaunchFileAsync(file) (without the options argument) - opens the pdf file in Edge (my default PDF app)

Edge is the default app that used to open pdf file. And you could edit it in Setting page.

Setting -> Apps-> Default Apps-> Choose default apps by file type.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36