How to Retrieve Local and Web Paths of an Excel Workbook from OneDrive using JavaScript API

Kashif Bashir Bhatti 36 Reputation points
2025-02-18T16:52:25.0666667+00:00

A OneDrive folder has been synchronized on a local machine, allowing workbooks to be opened directly from this folder. The local and web paths can be obtained using the Info => Copy path and Info => Copy local path options, as highlighted in the image below image.

The challenge is retrieving both paths in an Excel add-in developed using the JavaScript API. The Office.context.document.url property intermittently provides either the local path or the web path, but not both. Is there a method to obtain these paths from Excel using the JavaScript API, or are there any libraries, services, or hooks available to manipulate menu clicks to access this information, given that Excel already recognizes these paths?

Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office Development Other
Microsoft 365 and Office OneDrive For business Windows
Microsoft 365 and Office Excel For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Adrian Wu 0 Reputation points Microsoft Employee
    2025-03-18T08:52:54.53+00:00

    We currently have 2 ways to get Url via API. They are:

    • Office.context.document.url
    • Office.context.document.getFilePropertiesAsync(function (asyncResult) {const fileUrl = asyncResult.value.url;...}

    However, both of them only support online path. If you expect to add the ability to get local path as well, it would be very helpful if you could help us create a new post in our technical forum so that more people with similar requests can join the discussion and upvote for this idea.  

    Thank you for your feature suggestion and your active participation!!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.