0

I have a .docx file in OneDrive. If I click on it, it opens on Word Online. Then, there is a button that says Edit in Word that opens the current file in desktop Word (you have to provide credentials, of course).

Using the OneDrive API, I'm able to open a file directly in Word Online from my PHP application (since it provides the file URL), but now I'm trying to directly open it in Word Offline (and then, Word will prompt the credentials to the user).

TL;DR: I'm trying to reproduce the Edit in Word button behavior. How can I do this?

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
  • http://stackoverflow.com/questions/6265717/how-to-start-up-a-desktop-application-in-client-side – YVS1102 Dec 22 '16 at 14:29
  • @YVS1102 There's literally a button that says `Edit in Word` in a JS application with the office protocol `ms-word`. That answer you provided says you can't do this. Please read the question before randomly posting. – Christopher Francisco Dec 22 '16 at 14:39
  • my bad. I read this part twice `but now I'm trying to directly open it in Word Offline (and then, Word will prompt the credentials to the user).` – YVS1102 Dec 22 '16 at 14:50

1 Answers1

1

To open a file in desktop Word from webapp you have to use ms-word protocol:

https://msdn.microsoft.com/en-us/library/office/dn906146.aspx

It looks like: ms-word:ofe|u|<url to file>. You should be able to trigger opening file by setting above url as a href attribute of a tag or by calling window.open() JS function.

But you need direct URL(not the web url or generated access link) and as far as I'm concerned API doesn't provide such one so you will have to construct it by yourself.

Direct link for OneDrive(personal) looks like: https://d.docs.live.net/{drive-id}/{file-path}.

You can get your drive id by calling an API(I will use Microsoft Graph because I'm familiar only with this one).

Call https://graph.microsoft.com/v1.0/me/drive/ and as a response you will get a JSON which includes id property and that's your needed drive id.

If you don't want to use Graph API but OneDrive API I guess the only part that changes is graph.microsoft.com and it becomes api.onedrive.com(but I'm not sure, look here for more info - https://dev.onedrive.com/getting-started.htm).

Next you need to provide path to file in your OneDrive. If file is located in root directory the direct url to file might look like this: https://d.docs.live.net/xxxxxxxxxx/Document1.docx.

That's basically all, now you should be able to open your file in desktop Word by using ms-word:ofe|u|https://d.docs.live.net/xxxxxxxxxx/Document1.docx.

kamilz
  • 168
  • 1
  • 12