Question

I would like to understand if reading data from a SPView gives better response time than reading directly from a SPList.

Basically I got this question as I have a SPlist with almost 30 columns, and I am trying to read only 3 columns in my code. Now I found out that in SP2013, it is possible to use SPQuery.ViewFieldsOnly property to ensure that data from selected columns is fetched. But my organization is currently using WSS 3.0 (WSS3.0 does not have a SPQuery.ViewFieldsOnly property). So I am thinking to create a view to fetch data. My SPList contains many items and I need to prepare a report on a button click event in a SPWebPart. So as you can understand, response time is important to me. I want to save as much execution time as possible by fetching only required fields from my SPList.

I am looking at the following code sample using SPView:

SPListItemCollection coll = web.Lists["ListName"].GetItems(web.Lists["ListName"].Views["ViewName"]);

Using SPList:

SPListItemCollection coll = web.Lists["ListName"].GetItems(web.Lists["ListName"]);

Will the SPView sample give a better response time assuming that I have many rows of data in the SPList? or is it the same?

Was it helpful?

Solution

YES, always query your list with CAML and assign view fields, simply cycling the listitemcollection will give you bad performance.

Calling a view means you're basically extracting the CAML from that view and using it to do a query. Meaning you'll have great performance. Recommended approach.

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