【问题标题】:C#, Microsoft Graph: Get the local path for a sharepoint library synced using OneDrive BusinessC#、Microsoft Graph:获取使用 OneDrive Business 同步的共享点库的本地路径
【发布时间】:2021-06-28 06:49:51
【问题描述】:
对于业务应用程序,我们将文档存储在 Sharepoint Online 上(word、pdf、powerpoint...)。该应用程序使用 Microsoft Graph 来获取文件和元数据列表。但是,所有用户都将共享点站点与他们的 OneDrive 业务“同步”,以供本地存储/离线使用。
用户会看到一个“打开文件”按钮,允许他打开文件并进行更改。但是如何使用microsoft graph api打开本地文件而不是浏览器打开文件的在线版本。
或者至少获取文件的本地“路径”,以便可以使用 Process.Start 打开它
【问题讨论】:
标签:
c#
sharepoint
microsoft-graph-api
onedrive
【解决方案1】:
目前设法通过使用注册表的类似技术来做到这一点。尽管查看了我发现的所有谷歌结果,但这些年来注册表项和位置发生了很大变化。所以肯定会更喜欢 Microsoft.Graph 内置的“官方”方法或使用 ms-onedrive: 链接,类似于 ms-word: 链接等...
public static class ListExtensions
{
public static String GetLocalPath(this List item)
{
var onedriveKey = Registry.CurrentUser.OpenSubKey(@"Software\SyncEngines\Providers\OneDrive");
foreach (var subkeyName in onedriveKey.GetSubKeyNames())
{
var subkey = onedriveKey.OpenSubKey(subkeyName);
var url = subkey.GetValue("UrlNamespace").ToString().Trim('/');
if (url == item.WebUrl)
return (String) subkey.GetValue("MountPoint");
}
return null;
}
}
public static async Task<String> GetDocumentLocalPath(DocumentSharepoint document)
{
var list = await GetList(document.Library);
var path = list.GetLocalPath();
if (path == null)
return null;
return $"{path}/{document.FullName}";
}