Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks for your reply. –  Ramalingam Dec 27 '11 at 6:36
    
Thanks you so much! –  Сергій Mar 20 '13 at 10:59
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.