C# OneDrive for Business / SharePoint: get server

2019-06-21 05:06发布

问题:

I'm writing a WPF C# application, and would like to obtain the SharePoint URL of a locally synced file.

In Windows Explorer, the user can right click on a file in the synced OneDrive folder, select "OneDrive for Business" menu and "Copy link". This provides the SharePoint URL of the synced file. Is there a way to replicate this in C#?

At the moment, if I reference the file using a FileOpenDialog from within my application, I only get the local physical path (e.g. c:\onedrive...\file.txt). How can I use the locally synced file to get the SharePoint URL?

回答1:

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\uid41890\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) Edit: unfortunately the GetFile function seems only to be available on the server side.

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.