dddd
dddd

Reputation: 31

Getting Onedrive link of current Word Online file from Task Pane Add-on

I was wondering if it was possible to get the onedrive link from a TaskPane add-on. From what I know, If I make a new Word Online document, it saves it automatically to my one drive so I was wondering if I could retrieve the URL somehow. Specifically, I want the link where when you login on one drive and right click a document and choose get link, it gives you a URL. This is the URL I want.

Thanks

Upvotes: 1

Views: 78

Answers (2)

Miro J.
Miro J.

Reputation: 4974

There is an easy way to get the URL of the document. The JavaScript API for Office 1.1 has a object Office.context.document. You can use its property url to get the path to the document - local or cloud.

var urlDoc = Office.context.document.url;
console.log(urlDoc)

For more details, check this: https://msdn.microsoft.com/en-us/library/office/fp161057.aspx

Upvotes: 0

Michael Saunders
Michael Saunders

Reputation: 2668

Yes, the code is below. The key method here is getFilePropertiesAsync. OneDrive UI might give you a different link depending on whether you're sharing the document (and add-ins aren't aware of how the document is shared). But it's the correct URL of the document and can be used by anyone with permission to access it.

Office.context.document.getFilePropertiesAsync(
  function (asyncResult) {
    if (asyncResult.status == "failed") {
      doWhateverWith("Action failed with error: " + asyncResult.error.message);
    } else {
      doWhateverWith("The document location is: " + asyncResult.value.url);
    }
  }
);

-Michael (PM for Office add-ins)

Upvotes: 0

Related Questions