.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Retrieve Large Number of Items from SharePoint List

Posted By:Sagar Pardeshi       Posted Date: July 15, 2014    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

Retrieve Large Number of Items from SharePoint List
 

Introduction

In this blog 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

Let's 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();
            }



 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend