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
.