Home > Enterprise >  How to open a PDF file in its associated application in a UWP application?
How to open a PDF file in its associated application in a UWP application?

Time:09-30

I have a UWP application that contains a PDF file in a folder called Images and I need to open the file in its associated application on Windows (a browser or a PDF reader). I've seen all the similar questions posted here and came to the code below but it didn't work. Any suggestion?

    private async void nviHelp_Tapped(object sender, TappedRoutedEventArgs e)
    {
        string pdfFile = @"Images\witmnlptbr.pdf";

        var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(pdfFile);

        if (file != null)
        {
            var success = await Windows.System.Launcher.LaunchFileAsync(file);
        }

    }

CodePudding user response:

The enter image description here

  1. Make sure that the default app for the PDF file is set to the browser or the PDF reader in the Settings system.

enter image description here

  • Related