Juan Pablo Garcia Coello
Juan Pablo Garcia Coello

Reputation: 3232

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?

Upvotes: 7

Views: 4058

Answers (1)

Rob Caplan - MSFT
Rob Caplan - MSFT

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

Related Questions