1

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?

0

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.

  • Ohk, now I understand how querying the view can result in a better response time. I wish I had known this before. Thanks a lot! – Jzf Sep 26 '14 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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