【问题标题】:Sharepoint online - Not returning items in a specific view in ListSharepoint online - 不返回列表中特定视图中的项目
【发布时间】:2021-03-28 01:40:13
【问题描述】:

我正在尝试从特定视图中获取项目列表。下面是代码

Microsoft.SharePoint.Client.List _lists = context.Web.Lists.GetByTitle("Invoice Register");  
context.Load(_lists);
context.ExecuteQuery();
int listCount = _lists.ItemCount; // i get 49000+ count here
                
View _listsView = _lists.Views.GetByTitle("IT Testing");
context.Load(_listsView);
context.ExecuteQuery();
                

CamlQuery _query = new CamlQuery();
_query.ViewXml = _listsView.ViewQuery;


Microsoft.SharePoint.Client.ListItemCollection items = _lists.GetItems(_query);           
context.Load(items);            
context.ExecuteQuery();
int _viewCount = items.Count; // I get nothing here.
           

我得到的错误是尝试的操作被禁止,因为它超过了管理员强制执行的列表视图阈值

我已经创建了索引

我已将“IT 测试”的限制设置为 5000,如此处所示。

如果有人可以指导,那将很有帮助。我已经浏览了所有我能找到的链接。

问候

【问题讨论】:

  • 这是 SharePoint 和包含 5000 多个项目的列表的一个已知问题。你可以试试这个natechamberlain.com/2018/05/21/… 或者使用 Graph API
  • 我已经索引了列@vhr

标签: c# sharepoint sharepoint-online sharepoint-list


【解决方案1】:

@Ather Siddiqui,

没有直接的方法来获取视图下的项目,因为视图只有查询模式并且没有任何项目。 caml查询可能会获取到视图下的相同项目,但会触发列表视图阈值。

@user2250152 提供了一个很好的方法,通过 Pagination 可以获得超过 5000 个条目。如果您想使用视图查询,您可以将查询更改如下:

List tList = context.Web.Lists.GetByTitle("My test list");
            CamlQuery camlQuery = new CamlQuery
            {
                ViewXml = @"<View><Query><Where><Gt><FieldRef Name='ID' /><Value Type='Counter'>20</Value></Gt></Where></Query><OrderBy><FieldRef Name ='FileLeafRef' /></OrderBy><RowLimit>4990</RowLimit></View>"  // your view query
            };

            var itemColl = new List<ListItem>();
         
            do
            {
                ListItemCollection listItemCollection = tList.GetItems(camlQuery);
                context.Load(listItemCollection);
                context.ExecuteQuery();    
                
                //
                itemColl.AddRange(listItemCollection);
                camlQuery.ListItemCollectionPosition = listItemCollection.ListItemCollectionPosition;               

            } while (itemColl.Count < 999); //view row limit   

            Console.WriteLine(itemColl);    

【讨论】:

    【解决方案2】:

    我正在使用此代码加载很多项目。

    var itemsPerPage = 100;
    var query = CamlQuery.CreateAllItemsQuery(itemsPerPage);
    var loadMoreItems = false;
    do
    {
        var items = list.GetItems(query);
        ctx.Load(items);
        ctx.ExecuteQuery();
    
        loadMoreItems = items.Count == itemsPerPage;
        query.ListItemCollectionPosition = items.ListItemCollectionPosition;
     }
     while (loadMoreItems);
    

    它基于this

    CalmQuery.CreateAllItemsQuery

    【讨论】:

    • 这给了我 IT 测试视图中不存在的项目。我需要 IT 测试项目。
    猜你喜欢
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多