Query Large List in SharePoint

using (SPSite currentSite = new SPSite(SPContext.Current.Site.ID))
using (SPWeb currentWeb = currentSite.OpenWeb("crm"))
SPList myList_TrainingRecords = currentWeb.Lists["Training Records"];
SPQuery qry = new SPQuery();
qry.Query = "<OrderBy Override=\"TRUE\">" + "<FieldRef Name=\"Title\" Ascending = \"true\" /></OrderBy>";
// Note: if the field name was changed from "Title" to something else in SharePoint , you will still need to use "Title" in your query. i.e., <FieldRef Name="Title"/>
// The field name is "InternalName" which means if it contains spaces you will need to use _x0020_ to replace the space. 
qry.RowLimit = 1999;

do {
SPListItemCollection listItemCollection = myList_TrainingRecords.GetItems(qry);
foreach (SPListItem item in listItemCollection)
// your code here
Response.Write(SPEncode.HtmlEncode(item["Title"].ToString()) + "
qry.ListItemCollectionPosition = listItemCollection.ListItemCollectionPosition;

} while (qry.ListItemCollectionPosition != null);

View More

This entry was posted in SharePoint 2010, Visual Studio 2010. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s