I am retrieving all items from list containing around 4000 items. But it seems to take longer time to fetch all items which is ~15 to ~22 seconds. Is there any best way to fetch all items from list in negligible time?
Following is the code i am using to fetch all items:
using (SPSite spSite = new SPSite(site))
{
using (SPWeb web = spSite.OpenWeb())
{
list = web.Lists["ListName"];
SPQuery query1 = new SPQuery();
string query = "<View>";
query += "<ViewFields>";
query += "<FieldRef Name='ID' />";
query += "<FieldRef Name='Title' />";
query += "</ViewFields>";
query += "<Query>";
query += "<Where>";
query += "<Eq>";
query += "<FieldRef Name='ColName'></FieldRef>";
query += "<Value Type='Boolean'>1</Value>";
query += "</Eq>";
query += "</Where>";
query += "</Query>";
query += "</View>";
query1.Query = query;
SPListItemCollection listItems = list.GetItems(query1);
}
}
Normally when it is taking this long to Retrieve items you are hitting a Boundary or limit.
First up you need to test putting a limit of your query, so you return less than 2000 items, or until you find when it starts becoming unbelievably slow.
Then you need to see if you can break your query up, or do multiple queries to get your items depending on this figure.
Cheers
Truez
Fetching many items in one shot is for sure not the best practice, or suggested way.
You have to look into alternative options, like
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.