Forum Xamarin.Forms

UWP LaunchUriAsync failing without error message

I have a UWP app, and I am trying to get it to ask the device to open a pdf in whatever manner it chooses.

The code looks like this:

async static partial void OpenFileWithNativeApp(string filepath)
        Device.BeginInvokeOnMainThread(async () =>
            Uri targetUri = new Uri(filepath);
            bool outcome = await Windows.System.Launcher.LaunchUriAsync(targetUri);

filepath is roughly: {file:///C:/Users/walter.fakename/AppData/Local/Packages/Guid/LocalState/PDFWhatever.pdf} . I can navigate to that place on my c drive, and the pdf is actually there.

When I run this code the outcome that is set by LaunchUriAsync is set to false, indicating that the Uri was not successfully launched. This is correct, as indeed, no other app launches the Uri. But it doesn't tell me how to fix it, such that the Uri would be successfully launched by whatever browser or pdf viewer the device associates with pdfs.

Does anyone see what I'm doing wrong?



Best Answer


Sign In or Register to comment.