如何使用 CSOM 针对 Sharepoint 2013 访问文件夹的 UniqueId

How can I access the UniqueId of a folder using CSOM against Sharepoint 2013

针对 SharePoint Online 使用以下代码和 CSOM 16.1 我能够检索文件夹列表:

var folderList = string.IsNullOrEmpty(parentRelativeUrl)
? sharePointContext.Web.Folders
: sharePointContext.Web.GetFolderByServerRelativeUrl(parentRelativeUrl).Folders;

sharePointContext.Load(folderList, items => items.Include(
item => item.Folders, 
item => item.Files,
item => item.Name, 
item => item.ServerRelativeUrl, 
item => item.Properties, 
item => item.UniqueId));

sharePointContext.ExecuteQuery();

当 运行 针对 SharePoint 的 2013 内部部署版本时,我的绊脚石似乎围绕着 UniqueId 字段。我得到的错误是:

Field or property "UniqueId" does not exist.

然后我尝试将我的 CSOM 版本降级到 2013,我可以看到文件夹 class 不包含 UniqueId 字段。

有没有办法在 2013 年检索此字段?

对于您目前的情况,我建议您查看 ClientObject.Path 属性,它可用于 SharePoint 2013。它不需要检索,因为它是内部 属性,将由API组成。对于我的测试,它包含以下值:

Console.WriteLine(folder.Path);
"GUID|GUID:site:GUID:web:GUID:folder:GUIDYOUNEED"

'GUIDYOUNEED'等于文件夹的UniqueId。

Item.Id 会帮助你.. 你只能选择可用的变量。键入项目的那一刻。帮助将为您提供与项目关联的操作和变量列表,您必须选择 "id" 才能获取项目的 uniqueId 要获取列表或文档库的 ID,您可以使用方法 "GetListByTitle".

 List doc = web.Lists.GetByTitle("Documents");
        clientContext.Load(doc);
clientContent.ExecuteQuery();

doc.id 将为您提供文档库的唯一 ID。