查询在线共享点列表时出错 [英] Error when consulting an online sharepoint list

查看:109
本文介绍了查询在线共享点列表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#vs 2013中有此代码块



namespace IndicadoresCartera
{
    public class SPQuery
    {
        public ClientContext clientContext;
        public Web site;
        public ListItemCreationInformation itemCreateInfo;
        static SPQuery queryService = new SPQuery();
        
        public void getClientes()
        {

            List clientesGet = clientContext.Web.Lists.GetByTitle("clients");
            CamlQuery query = new CamlQuery();

            query.ViewXml = "<View><ViewFields><FieldRef Name='ID' /></ViewFields></View>";

            ListItemCollection ToDoClientes = clientesGet.GetItems(query);
            clientContext.Load(ToDoClientes);
            clientContext.ExecuteQuery();

            foreach (var cl in ToDoClientes.ToList())
            {
                if (cl["Title"] != null && cl["code"] != null && cl["name"] != null)
                {
                    List targetList = queryService.site.Lists.GetByTitle("Indi");
                    ListItem inCartera = targetList.AddItem(queryService.itemCreateInfo);

                    inCartera["Proceso"] = "Cliente";    
                    inCartera["Inicio"] = cl["FechaSolicitud"];
                    inCartera["Fin"] = cl["FechaAsignacionCodigo"];
                    inCartera["EstadoFinal"] = "Cliente Creado";

                    queryService.createItem("indicators", inCartera);
                }
            }
        }
    }
}

The problem is that the list of clients has more than 2,000 records and how is online sharepoint I get an error of information:

An operation that is prohibited was attempted because it exceeds the list view threshold applied by the administrator

How can I consult the list so that it triagates all the data and with the the if filter?

推荐答案

我们可以使用 ListItemCollectionPosition 类根据项目相对于其集合的位置来实现分页列表项目检索.使用 RowLimit 元素可指定每页要返回的项目数.达到列表视图阈值限制时,这非常有用.

We can use the ListItemCollectionPosition class to implement paging list item retrieval according to the position of items relative to their collection. Use the RowLimit element to specify the number of items to return per page. It is very useful when list view threshold limit is reached.

以下代码供您参考:

using (ClientContext ctx = new ClientContext("siteUrl"))
{
   ctx.Credentials = new SharePointOnlineCredentials("test@something.onmicrosoft.com", GetSecureStringPassword());
   List list = ctx.Web.Lists.GetByTitle("ListName");
 
   CamlQuery camlQuery = new CamlQuery();
   camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"><RowLimit>30</RowLimit></View>";
 
   int intIndex = 1;
    
   //Creating a single buffer for storing all the ListItems
   List<ListItem> lstListItemCollection = new List<ListItem>();
 
   do
   {
       ListItemCollection listItemCollection = list.GetItems(camlQuery);
       ctx.Load(listItemCollection);
       ctx.ExecuteQuery();
 
       //Adding the current set of ListItems in our single buffer
       lstListItemCollection.AddRange(listItemCollection);
        
       //Reset the current pagination info
       camlQuery.ListItemCollectionPosition = listItemCollection.ListItemCollectionPosition;
 
       Console.WriteLine("Page:: " + intIndex++);
       Console.WriteLine("ListItemCollectionPosition:: " + camlQuery.ListItemCollectionPosition);
 
   } while (camlQuery.ListItemCollectionPosition != null);
}

更多信息:

https://sharepoint.stackexchange .com/questions/177592/how-to-query-list-with-5000-items-in-sharepoint-online

https://piyushksingh.com/2016/12/04/query-listitems-in-batches-sharepoint-online/

最好的问候,

丹尼斯


这篇关于查询在线共享点列表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆