Reputation: 3232
I have tried to launch a file from the computer in many ways, suppose is d:\a.pdf
1.- Tried with Launcher.LaunchFileAsync but needs StorageFile that should be GetFileFromPathAsync but as everybody knows W10 apps are unauthorized to open such that path.
2.- Tried using file:/// like file:///d:/a.pdf but it simply returns false
var success = await Launcher.LaunchUriAsync(new Uri("file:///d:/a.pdf", UriKind.Absolute), options);
3.- Launcher.FindFileHandlersAsync() neither returns empty.
So is there any way to launch files?
Upvotes: 7
Views: 4058
Reputation: 21899
There is no way to launch files from paths that the app doesn't have permissions to read. Apps don't have access to d:\
You can use LaunchUriAsync to launch files by path from within the app package or app data directories, but not elsewhere. Using the ms-appx: or ms-appdata: protocols is a cleaner way to address those locations.
If you have permission then you can get a StorageFile. This will allow launching files from libraries, locations chosen via FilePicker, files clicked on to launch the app (though that would be circular), etc.
Upvotes: 5