C#sharepoint列表项集合

时间:2018-03-07 07:26:31

标签: c# list sharepoint threshold

QUES。我有这个方法机智返回类型为“列表项集合”,我在SharePoint中的列表包含超过5000个项目。为了克服这个门槛,我需要通过设置行限制来批量获取物品,但我不知道要放在什么位置?这样返回类型也是'ListItemCollection'(SharePoint客户端上下文)。请帮忙

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;
}

2 个答案:

答案 0 :(得分:0)

我是这样做的,希望它是一个解决方法,并会帮助你

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;
    }

答案 1 :(得分:0)

您可以在caml查询中设置rowlimit。

例如:

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>";

然后,使用ListItemCollectionPosition属性进行分页。

选中sample