DataServiceQuery IEnumerator from Sharepoint returning only 1000 items

436 Views Asked by At

I have a Sharepoint 2010 list, and I am using System.Data.Services.Client.DataServiceQuery to get the list into a C# List. However, when I enumerate through the list, I am limited to 1000 items.

I did some research and found that Active Directory default limits this number to 1000 so it makes sense that it would be limited in Sharepoint as well, but I would like to increase this number.

Can anyone provide some steps to find the MaxPageSize within Sharepoint, or wherever it is located so I can get back more than 1000 items in my C# program?

1

There are 1 best solutions below

0
On

The Problem cames from Pagination

Now depending on how your service is configured, you may not receive all of your rows. In our case, we only got 1000. This means the service is only configured to return a maximum of 1000 per query. To work around this, you must paginate your requests:

    var projects = from project in dc.ITProjects
                  orderby project.Id
                  select new
                  {
                      Phase = project.Phase.Value,
                      ProjectName = project.Project
                  }
                  ;

    int recordCount = projects.Count();
    int page = 0;
    int pageSize = 100;

    while(page*pageSize < recordCount)
    {
        foreach (var project in projects.Skip(page * pageSize).Take(pageSize))
        {
            Output0Buffer.AddRow();
            Output0Buffer.C1 = project.Phase;
            Output0Buffer.C2 = project.ProjectName;
        }
        page++;
    }