Question

I have an requirement of fetching bulk data from sharepoint list using SPquery. Here is the code

DataTable dt=new DataTable();
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope=\"SiteCollection\"";
query.Query = "<Where><Eq><FieldRef Name='Title'><Value Type='Text'>s</Value></Eq></Where>";
query.ViewFields = "<FieldRef Name='Title'>";
query.ViewFieldsOnly = true;
query.QueryThrottleMode = SPQueryThrottleOption.Strict;
splist.EnableThrottling = false;
query.RowLimit = 2000;
 do
                        {
                            SPListItemCollection myItems = splist.GetItems(query);
                            if (dt == null || dt.Rows.Count <= 0)
                                dt = myItems.GetDataTable();
                            else
                                dt.Merge(myItems.GetDataTable());
                            query.ListItemCollectionPosition = myItems.ListItemCollectionPosition;
                        }
                        while (query.ListItemCollectionPosition != null);

If I didn't set splist.EnableThrottling = false I am unable to retrieve bulk data from sharepoint list. Programatically If I have set the splist.EnableThrottling = false I am getting Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack error,I have gone through the msdn article http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.enablethrottling.aspx.This property requires Farm Admin Permission.

So how could I retrieve bulk data without using splist.enablethrottling property.Could anyone help me to solve this issue ?

Was it helpful?

Solution

SharePoint Server 2010 provides a new class named ContentIterator that you can use to query lists without hitting these limits. You should consider using this class if you need to run a query that will return more than 5,000 rows of data.

OTHER TIPS

You can use cycle with paging. Get 1000 items and add it to DataTable while query.ListItemCollectionPosition isn't null.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top