microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.26k stars 672 forks source link

HyperlinkButton refuses to navigate to file:// URI #2357

Open DHowett-MSFT opened 4 years ago

DHowett-MSFT commented 4 years ago

Describe the bug

<HyperlinkButton Content="All URIs are created Equal"
                 NavigateUri="file:///C:/sad.html" />

Clicking this button results in nothing happening (not even an exception).

Steps to reproduce the bug

As above. Have a file called sad.html in C:.

Terminal's use case was embedding third-party notices as an HTML file in our package and then launching the browser to that file.

Expected behavior It works.

Version Info Windows 10.0.19041.0 This is a platform HyperlinkButton, so I presume it doesn't matter which version of MUX is in use.

Windows 10 version Saw the problem?
Insider Build (19041) Yes
November 2019 Update (18363) Untested
May 2019 Update (18362) Untested
October 2018 Update (17763) Untested
April 2018 Update (17134) Untested
Fall Creators Update (16299) Untested
Creators Update (15063) Untested
Device form factor Saw the problem?
Desktop Yes
Mobile Untested
Xbox Untested
Surface Hub Untested
IoT Untested
chrisglein commented 3 years ago

Adding information from duplicate of linked PowerToys issue: https://github.com/microsoft/PowerToys/issues/7819

crutkas commented 3 years ago

Is this one related to running under admin?

DHowett commented 3 years ago

No.

jevansaks commented 3 years ago

I suspect this is because LaunchUriAsync and ShellExecute are not the same. I don't see "file:" as one of the schemes in https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app (though "file" is in the list of reserved schemes). I also see that there's "LaunchFileAsync" that got added so presumably we are supposed to call that for file paths ... though it's weird that file scheme isn't invoking that same LaunchFileAsync path.

@jonwis @drustheaxe do you know what's up here?

Jay-o-Way commented 3 years ago

@crutkas @DHowett-MSFT I'm no expert, but I'm thinking the NavigateURI is NOT intented to be used with files in the first place. I mean, the word "navigate" sounds like the key word here. Opening a file is something totally different then navigating to a (web or settings) page. Check out https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-the-default-app-for-a-file. You should use the Click="" function.

Besides that, does the app have access to the file or location? Just came across this: https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions#accessing-additional-locations amd https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions#locations-that-uwp-apps-can-access.

Jay-o-Way commented 3 years ago

I suspect this is because LaunchUriAsync and ShellExecute are not the same. I don't see "file:" as one of the schemes in https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app (though "file" is in the list of reserved schemes). I also see that there's "LaunchFileAsync" that got added so presumably we are supposed to call that for file paths ... though it's weird that file scheme isn't invoking that same LaunchFileAsync path.

@jevansaks The title says enough: "Launch the default APP for a URI"