4
votes

I am looking for a way to derive the OneDrive file URL for a file cached to my local OneDrive folder? The only thing I can think of is hardcoding some root URLS for each of the OneDrive folders I have, but this seems nasty!

Does anyone know of any OneDrive client API that lets query a URL based on the local file path?

My use case: I am trying to attach to and open instance of an Excel workbook. I used to be able to do this Marshal.BindToMoniker(_workbookPath);

However it appears that Excel is now registering the OneDrive URL in the ROT rather than the local file path. This this happened with the update that brought the new auto-save feature to Excel 2016 I think, that seems to be about the time my existing code broke.

There is a similar unanswered question here: C# OneDrive for Business / SharePoint: get server path from locally synced file

2
are you able to use BindToMoniker() on the onedrive URL? How?Ben

2 Answers

1
votes

I am also looking at a solution for getting the SharePoint url to a file in OneDrive Synced File Explorer. I have noticed you get under C:\Users\%username%\AppData\Local\Microsoft\OneDrive\settings\Business1{GUID}.ini a mapping between your OneDrive synced folder and the SharePoint GUID Example:

libraryScope = 1 630c2a866d9c458b81060eff107887ed+1 5 "GUIDEs" "Documents" 4 "https://continental.sharepoint.com/teams/team_10000035" "8d4b558f-7b2e-40ba-ad1f-e04d79e6265a" e0266a43caf347238f684bab486f4e51 e0d25dcb1a014f5f86d787984f6327c2 4f86b3e3e54e42e0bb0f7a58eadf0335 0 "" 0 4cde5c00-3fe3-4162-b831-d8ef440e1593
libraryFolder = 0 1 8bbfe07dfeff41cea7ab5da4a554592a+1 1558084235 "D:\DSUsers\uid41890\Continental AG\GUIDEs - General" 2 "General" bd0c1b7c-2a1f-4492-8b1b-8e152c9e0c26

You also have this mapping in the registry Computer\HKEY_CURRENT_USER\Software\Microsoft\OneDrive\Accounts\Business1\ScopeIdToMountPointPathCache

From the GUID you could get the path using SPWeb.GetFile(Guid)

If you can make a standalone function given a local OneDrive file path that returns the SharePoint url, I would greatly appreciate you share your solution here.

1
votes

Might want to use the following key instead:

HKEY_CURRENT_USER\Software\SyncEngines\Providers\OneDrive

This includes the following registry values: UrlNamespace: (SharePoint site URL) MountPoint: (local driver location)

It does appear to include old values which are no longer synced - but it shouldn't be too hard to check against

HKEY_CURRENT_USER\Software\Microsoft\OneDrive\Accounts\Business1\ScopeIdToMountPointPathCache

or

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager

for paths that are being actively synced.