简体   繁体   English

C#共享点列表项集合

[英]C# sharepoint List Item Collection

Ques. 没错 I have this method wit return type as 'List Item Collection'and my list in SharePoint contains more than 5000 items. 我的返回类型为“列表项集合”,并且在SharePoint中我的列表包含5000多个项。 In order to overcome the threshold, I need to fetch items in batches by putting row limit but I do not know what to put in the place of ?? 为了克服该阈值,我需要通过设置行限制来批量获取项目,但是我不知道该用什么代替? so that the return type is also 'ListItemCollection'(SharePoint Client Context). 因此返回类型也是“ ListItemCollection”(SharePoint客户端上下文)。 Please help 请帮忙

private static ListItemCollection GetItemsFromSharePointSiteList(string strListName, string strCamlQuery, ClientContext clientContext)
{
    try
    {               
        ListItemCollectionPosition itemPosition = null;

        List listIPPMilestonesLE = clientContext.Web.Lists.GetByTitle(strListName);
        CamlQuery query = new CamlQuery();
        query.ViewXml = strCamlQuery;
        query.DatesInUtc = false;

        //  ListItemCollection itemColl = new ListItemCollection();

        do
        {
            Microsoft.SharePoint.Client.ListItemCollection listItemCollection = listIPPMilestonesLE.GetItems(query);
            clientContext.Load(listItemCollection);
            clientContext.ExecuteQuery();

            foreach (ListItem oListItem in listItemCollection)
            {
                 ??
            }

            itemPosition = listItemCollection.ListItemCollectionPosition;

        } while (itemPosition != null);

        return null;
    }
    catch (Exception exc)
    {
        ErrorLog.Error(exc);
    }

    return null;
}

I did it like below, Hope it will be a workaround and will help you 我的操作如下,希望这是一种解决方法,对您有所帮助

private static List<ListItem> GetItemsFromSharePointSiteList(string strListName, string strCamlQuery, ClientContext clientContext)
    {
        try
        {
            ListItemCollectionPosition itemPosition = null;

            List listIPPMilestonesLE = clientContext.Web.Lists.GetByTitle(strListName);
            CamlQuery query = new CamlQuery();
            query.ViewXml = strCamlQuery;
            query.DatesInUtc = false;

            var itemColl = new List<ListItem>();

            do
            {
                Microsoft.SharePoint.Client.ListItemCollection listItemCollection = listIPPMilestonesLE.GetItems(query);
                clientContext.Load(listItemCollection);
                clientContext.ExecuteQuery();

                //
                itemColl.AddRange(listItemCollection);

                itemPosition = listItemCollection.ListItemCollectionPosition;

            } while (itemPosition != null);

            return itemColl;
        }
        catch (Exception exc)
        {
            ErrorLog.Error(exc);
        }

        return null;
    }

You could set rowlimit in caml query. 您可以在caml查询中设置rowlimit。

For example: 例如:

CamlQuery query = new CamlQuery();
                query.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                 "<Value Type='Number'>1</Value></Geq></Where></Query><RowLimit>100</RowLimit><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/></ViewFields></View>";

Then, Paging with ListItemCollectionPosition property. 然后,使用ListItemCollectionPosition属性进行分页。

Check this sample . 检查此样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM