sharepoint - 如何在 CSOM 请求中包含项目的 FieldValues

标签 sharepoint sharepoint-2013 csom

我正在尝试使用客户端对象模型 (CSOM) 从 SharePoint 中提取所有项目信息。以下是我获取项目信息的方式:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description));

projectContext.Load(projectContext.LookupTables, c => c.Include(f => f.Id, f => f.Entries));
projectContext.Load(projectContext.Web.SiteUsers);
projectContext.ExecuteQuery();

但是,我还需要从这些项目中检索 FieldValues 属性,但我不知道如何将其包含在同一查询中。从上面的代码中检索项目后,我找到了如何在项目级别执行此操作,如下所示:

var pubProject = project.IncludeCustomFields;
projectContext.Load(pubProject);
projectContext.Load(pubProject.CustomFields);

projectContext.ExecuteQuery();

var fieldValues = pubProject.FieldValues;

现在 pubProject 将包含 FieldValues 信息,但对所有项目使用该方法变得太慢(调用 SharePoint 需要 1 - 4 秒),因为我需要为每个项目提出额外的请求以及最佳实践CSOM 就是尽可能少地调用。

如果我在 include 字段中包含 FieldValues,如下所示:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description, f => f.FieldValues));

我收到以下错误:

The query expression 'f.FieldValues' is not supported.

最佳答案

我认为您需要将 f => f.CustomFields 放入 .IncludeWithDefaultProperties 语句中,而不是 f.FieldValues -- 加载 CustomFields 应导致填充 FieldValues

关于sharepoint - 如何在 CSOM 请求中包含项目的 FieldValues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29850494/

相关文章:

c# - 为什么我得到 i :0#. w|domain\\username 和 RunWithElevatedPrivileges domain\apppool?

shell - 使用Power Shell获取具有页面布局的SharePoint页面列表

SharePoint - 如何在列表定义中使用 <RowLimit>

web-services - 10 分钟的写入进度 PowerShell

c# - 将文档上传到 Sharepoint 时添加元数据

sharepoint - 类似于 SiteUserInfoList 但适用于所有共享点用户

CSS 条件注册不起作用

javascript - 没有 'Access-Control-Allow-Origin' header

azure - 使用经过身份验证的 Azure AD 用户对 CSOM 进行身份验证

javascript - 通过 JSOM 获取当前用户更改的项目