c# - 无法在 C# 中使用 CAMLQuery 从 SharePoint 列表中检索列表项

标签 c# azure sharepoint caml

我无法使用 C# 中的 CAMLQuery 获取 SharePoint 列表中的列表项。我拥有管理员权限,并且能够获取列表的列名称,但获取列表项计数为 0。

有人可以帮我解决这个问题吗?下面是代码。这里我们得到的“collListItem”值为 0

  cc.Load(cc.Web, p => p.Lists);
            cc.ExecuteQuery();
            var lst = cc.Web.Lists.GetByTitle("Tracker List");
            cc.Load(lst.Fields);
            cc.ExecuteQuery();
            Console.WriteLine("\n Columns \n");

            foreach (var item in lst.Fields)
            {
                if (item.Hidden == false)
                {
                    Console.WriteLine(item.Title);
                }
            }
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='Created' Ascending='false' /></OrderBy></Query><RowLimit>5</RowLimit></View>";
            ListItemCollection collListItem = lst.GetItems(camlQuery);
            cc.Load(collListItem);
            cc.ExecuteQuery();

最佳答案

感谢您的回复,但它对我们不起作用。我们使用 app-id 和 Secret 来获取列表项,并使用 OfficeDevPnP Nuget。我们是 SharePoint 应用程序的所有者,并且已经为集合提供了完全控制权。我们能够获取特定列表的集合名称、字段名称,但不能获取 ListItems。示例代码仅供引用。

 using OfficeDevPnP.Core;
 using Microsoft.SharePoint.Client;

using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, appId, appSecret))
            {

                CamlQuery caml = new CamlQuery();
                caml.ViewXml = "<View><Query><OrderBy><FieldRef Name='Created' Ascending='false' /></OrderBy></Query><RowLimit>5</RowLimit></View>";

                var requestItems = clientContext.Web.Lists.GetByTitle(listName).GetItems(caml);
                clientContext.Load(requestItems);
                clientContext.ExecuteQuery();
                foreach (var item in requestItems)
                {
                    Console.WriteLine(item["Title"]);
                }
}

关于c# - 无法在 C# 中使用 CAMLQuery 从 SharePoint 列表中检索列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61136141/

相关文章:

c# - 使用属性路由时替换 Url.Link

c# - 在第 1 类中制作一个 2d 列表,在第 2 类中填写并在第 3 类中使用

c# - 计算14天序列顺序

azure - 我们如何自动缩放 Azure SQL 数据库的定价层?

c# - 使用 WebClient 从 SharePoint Online 下载文件

c# - 在 Dispose 方法中取消 dispose

azure - 如何将具有不同时间戳属性的多个 Azure IoT 设备的数据引入同一个 Azure 时序见解环境?

c# - 每个 azure 实例都运行 cron 吗?

javascript - 内容编辑器模式弹出窗口中的自定义 SharePoint 2013 列表/表单仅在表单所在的列表中打开...不在弹出窗口中

azure - 如何使用 Webhooks 从 Azure Function 中的 SharePoint 列表获取附件