Below is the common error during development:
- To avoid threshold error, we can
use below orderby query.
- Using Sorting on the returned list
- Implementing the search on the
items. Sample below which brings matched document string name on the page
- Complete Method
public static List<ListItem> GetAllListItemsInaList1(ClientContext ctx, string siteurl)
{
List<ListItem> items = new List<ListItem>();
ctx.Load(ctx.Web, a => a.Lists);
ctx.ExecuteQuery();
List list = ctx.Web.Lists.GetByTitle("EngagementDocumentLibrary");
ListItemCollectionPosition position = null;
int rowLimit = 4999;
var camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='RecursiveAll'>
<Query>
<OrderBy Override='TRUE'><FieldRef Name='ID'/></OrderBy>
</Query>
<ViewFields>
<FieldRef Name='FileLeafRef'/><FieldRef Name='File_x0020_Type' /><FieldRef Name='FileRef' /><FieldRef Name='Editor' />
</ViewFields>
<RowLimit Paged='TRUE'>" + rowLimit + "</RowLimit></View>";
do
{
ListItemCollection listItems = null;
camlQuery.ListItemCollectionPosition = position;
listItems = list.GetItems(camlQuery);
ctx.Load(listItems);
ctx.ExecuteQuery();
position = listItems.ListItemCollectionPosition;
items.AddRange(listItems.ToList());
}
while (position != null);
items = items.OrderBy(item => item.FieldValues["FileLeafRef"]).ToList();
return items;
}
No comments:
Post a Comment