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?

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
2,176 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,321 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,058 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,345 questions
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.