Tuesday, April 25, 2017

How to limited number of Rows in return in Data Loading with SharePoint CSOM?

when we load list item from a large document library, the process will hang due to large volumn of items.

it is quite easy to improve the performance to limited the number of rows return from the query. we just need to set the ViewXml property from teh CamlQuery object.

limitedQuery.ViewXml = "<View><RowLimit>50</RowLimit></View>";


 class Program
    {
        static void Main(string[] args)
        {

            string siteUrl = "http://SharepointSever";

            SP.ClientContext clientContext = new SP.ClientContext(siteUrl);

            SP.List oList = clientContext.Web.Lists.GetByTitle("My Documents");
            SP.CamlQuery limitedQuery = new SP.CamlQuery();
            limitedQuery.ViewXml = "<View><RowLimit>50</RowLimit></View>";

            SP.ListItemCollection collListItem = oList.GetItems(limitedQuery);

            clientContext.Load(collListItem);

            clientContext.ExecuteQuery();

            foreach (SP.ListItem oListItem in collListItem)
            {
                Console.WriteLine("ID: {0} \nTitle: {1}", oListItem.Id, oListItem["Title"]);
            }
            Console.ReadLine();

        }
    }

No comments:

Post a Comment