locked
Launching file based on file extension instead of protocol

    Question

  • Currently in my Metro app I allow the user to download various files, such as a Word document.  I am calling this method with the URI to the Word document.

    http://msdn.microsoft.com/en-us/library/windows/apps/hh701480.aspx

    This works but is clunky at best as it is based on protocol (HTTP) so launches the default browser to download the file, then you have to open the downloaded file to view it.

    My question, is there a way to make this more seamless where I could launch the file based on extension via the URI or even a way to download the file in the background saving it to My Documents and then passing the file location into a Windows API method that would launch it based on the default app that handles that file extension?


    Bret Zarkiewicz

    Friday, July 20, 2012 1:04 PM

Answers

  • Bret,

    SkyDrive is not handing the file off to Word.  What you are seeing is standard Internet Explorer functionality.  If you pass a stream in a URL to Internet Explorer, it gets intercepted first by a component called URLMON.dll.  URLMON in turn does... well to make a long story short and simplify it, Word has registered itself to handle documents in a URL like this.  URLMON can talk to Word (sort of) to invoke it.

    You will need to download the file to a temp location, then open the file from there using LaunchFileAsync.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, July 24, 2012 7:17 PM
    Moderator

All replies

  • More information on this, using the SkyDrive Metro app, you can open files directly from a URI so there might be another call than the one I presented that could do this in a more seamless way.

    In SkyDrive Metro app, when you click a file to download, it switches to desktop mode, displays a warning (there is where you can see the path to the file is a URI) and then it opens the file in Word.  Here is the URI of the file I see in the warning message (note: clicking this in the browser isn't going to do anything).

    https://d.docs.live.net/701fba39566ae381/test_doc.docx


    Bret Zarkiewicz

    Friday, July 20, 2012 1:34 PM
  • Friday, July 20, 2012 2:10 PM
    Moderator
  • That call uses the IStorageFile interface, is there a way to convert a URI to that interface?  I know I tried just dumping the URI into that call and it bombed out.

    Bret Zarkiewicz

    Friday, July 20, 2012 2:14 PM
  • Hi Bret,

    You could use xhr to stream the file down to your local temp directory and then open it from there.

    -Jeff


    Jeff Sanders (MSFT)

    Friday, July 20, 2012 2:17 PM
    Moderator
  • Yeah, I have thought of that.  How is SkyDrive doing it because it is presenting the URI in the warning message before opening it.  So it appears there is a way to do it without downloading the file to disk first.

    Bret Zarkiewicz

    Friday, July 20, 2012 2:22 PM
  • Hi Bret,

    Fire up ProcessMonitor and check on the file activity.  That may give us some insight as to whether or not SkyDrive is using temp files (I believe it is).

    http://technet.microsoft.com/en-us/sysinternals/bb896645

    -Jeff


    Jeff Sanders (MSFT)

    Friday, July 20, 2012 2:24 PM
    Moderator
  • The warning message is coming from Microsoft Word and the SkyDrive app isn't downloading the file to a temp location.  It is if the SkyDrive app is handing the URI directly to Microsoft Word.  Does that sound right?

    Bret Zarkiewicz

    Friday, July 20, 2012 4:32 PM
  • Anyone else have any input/suggestions on this topic?  SkyDrive is definitely handing off to Word in a seamless manner so there must be an API call we can use to leverage this same functionality.

    Bret Zarkiewicz

    Tuesday, July 24, 2012 2:15 PM
  • Bret,

    SkyDrive is not handing the file off to Word.  What you are seeing is standard Internet Explorer functionality.  If you pass a stream in a URL to Internet Explorer, it gets intercepted first by a component called URLMON.dll.  URLMON in turn does... well to make a long story short and simplify it, Word has registered itself to handle documents in a URL like this.  URLMON can talk to Word (sort of) to invoke it.

    You will need to download the file to a temp location, then open the file from there using LaunchFileAsync.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, July 24, 2012 7:17 PM
    Moderator