Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching files from path in Windows 10 UWP

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?

like image 245
Juan Pablo Garcia Coello Avatar asked Aug 18 '15 17:08

Juan Pablo Garcia Coello


1 Answers

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.

like image 93
Rob Caplan - MSFT Avatar answered Sep 28 '22 07:09

Rob Caplan - MSFT