Retrieve large number of items from SharePoint List

InfoPath alternatives for form designing SharePoint

In this Article we explore to retrieve large number of items with a better performance we can either user SPQuery or PortalSiteMapProvider Class. Read more with examples. Retrieving large number of items from SharePoint List.

If you have to retrieve a large number of items and also need a better performance then you should use one of the method below:
– Using SPQuery
– Using PortalSiteMapProvide

Read some SharePoint tutorials on:

Lets see the example for both the method



SPQuery:

using (SPSite CurrSite = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb CurrWeb = CurrSite.OpenWeb())
{
SPQuery curQry = new SPQuery();
curQry.Query = “<Where><Eq><FieldRef Name=’Dept’/> <Value Type=’Text’>Sharepoint</Value></Eq></Where>”;
curQry.RowLimit = 100;
SPList curList = CurrWeb.Lists[“Dept”];
SPListItemCollection curItems = curList.GetItems(curQry);
foreach (SPListItem curItem in curItems)
{
string ResultTitle = curItem[“Title”].ToString();
}
}
}

PortalSiteMapProvide:

The Class includes a method called GetCachedListItemsByQuery that retrieves data from a list based on an SPQuery object that is provided as a parameter to the method call.

The method then looks in its cache to see if the items already exist. If they do, the method returns the cached results, and if not, it queries the list , store the results in cache and returns them from the method call.

//Get Current Web
SPWeb curWeb = SPControl. GetContextWeb(HttpContext.Current);
//Create the Query
SPQuery curQry = new SPQuery();
curQry.Query = “<Where><Eq><FieldRef Name=\’Category\’/><Value Type=\’Text\’> Sharepoint </Value></Eq></Where>” ;
//Get Portal Map Provider
Portal SiteMapProvider ps = PortalSiteMapProvider.WebSiteMapProvider;
PortalWebSiteMapNode pNode = TryCast (ps.FindSiteMapNode (curWeb. ServerRelativeUrl), PortalWebSiteMapNode);
//Get the items
Pltems = ps.GetCachedListItemsByQuery (pNode, “Dept”, curQry, curWeb);
//Enumerate all resulting Items
foreach(PortalListItemSiteMapNode curItem in pItems)
{
string ResultItemTitle = curItem[“Title”]. ToString();
}

Hope this will be helpful.

Similar SharePoint 2013 Tutorials


About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →

Leave a Reply