Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a file in Windows Explorer from a Windows 8 app?

I want to write a function that, quite simply minimises my Windows 8 immersive app, and opens a file in explorer - preferably if the file is in a folder with multiple files, with the file highlighted.

 public async void OpenFile( string filePath)
 {
     StorageFile File = await StorageFile.GetFileFromApplicationUriAsync
                              (new Uri(filePath, UriKind.RelativeOrAbsolute)); ;

     if (File != null)
     {
         await Launcher.LaunchUriAsync(new Uri(File.Path));
     }
 }

This code gives me a permissions error. Any ideas?

like image 538
Simon Kiely Avatar asked Jan 17 '13 17:01

Simon Kiely


2 Answers

As far as I recall it, MS will not allow it. The app should be design as if it's running in a sandbox, with limited rights.

You can access certain file system locations, like the app install directory, app data locations, and the Downloads folder, with Windows Store apps by default. Apps can also access additional locations through the file picker, or by declaring capabilities.

I've tried the protocol handler approach, but got rejected twice :D Even if you find a way to do this and still publish, it doesn't mean that MS won't change his mind and remove your app from the store.

Like Hans Passant was saying :

Scratch the idea, you cannot make this work.

like image 193
codingPear Avatar answered Nov 15 '22 18:11

codingPear


this is purely for an internal app from my point of view

This is the core problem with your intended approach. There is no concept of an "internal app" in the Windows Store ecosystem. The only possible way to get a Store app running on another machine is by acquiring a license key that you can only get from the Store.

This is easy to overlook when you are developing a Store app on your dev machine. It looks like this license key is not required to run and debug your app. But there actually is one, you get it when Visual Studio pesters you with a dialog once a month to re-acquire your developer license key. This is a temporary key, good for only one month, and purely meant to give you enough time to get your app running solidly. There is no mechanism to transfer that key to another machine or keep it (and the program) alive beyond the one month expiration.

You can of course still publish an internal app to the Store. But you'll be vetted for suitability and stability by the validation procedure like any other Store app. Not just a mechanical test like WACK performs, there are two people that will test your app before it can be published. They will not hesitate to reject your app when you do anything to try to work around the sandbox restrictions, including the protocol handler hack.

Once approved, it will be downloadable by any Windows 8 user. Including a hacker that would be interested in your internal company secrets and practices btw. Very convenient as well, he won't have to get out of his pajamas.

A typical line-of-business app is still a desktop app for the foreseeable future.


This answer requires an update, there's now a mechanism to publish apps from a dedicated server. This is called sideloading. The app still requires a certificate, and it costs big bucks, but can be deployed from a private server controlled by a private company instead of the Microsoft Store server.

An overview is available here.

like image 5
Hans Passant Avatar answered Nov 15 '22 19:11

Hans Passant