Performance enhancement tips while using CAML Query in SharePoint
Posted by Bipul Raman on July 24, 2016.Putting a lot of design customization, custom codes on SharePoint may cause several performance issues. But the main challenge for a developer is to fulfill all the feasible business requirement of client without hitting down the performance. Enhancing performance cannot be done in single step. In fact, at every step of coding you need to take care of it. You need to review every single line of code and justify if it is really needed or can be optimized in other way.
In this article, I will be discussing performance enhancement tips very specific to CAML Query. Whenever you are requesting any data from SharePoint, you use CAML query to filter it based on your parameters. You can use these parameters in CAML Query to enhance the performance.
Where
: To put conditions or filters such as equals, contains etc.OrderBy
: To order the data. Instead of manipulating data later, do it in CAML itself.ViewFields
: To load data from selective fieldsRowLimit
: To load data in limited counts
- When List Item Title is equal to 'Test'
- Ordering data in Ascending Order
- Loading data for only two fields: 'Title' & 'Code'
- Loading only 3 list items
<View> <Query> <Where> <Eq> <FieldRef Name="Title" /> <Value Type="Text">Test</Value> </Eq> </Where> <OrderBy> <FieldRef Name="Title" Ascending="True" /> </OrderBy> </Query> <ViewFields> <FieldRef Name="Title" /> <FieldRef Name="Code" /> </ViewFields> <QueryOptions> <ViewAttributes Scope="RecursiveAll" /> </QueryOptions> <RowLimit>3</RowLimit> </View>
<ViewAttributes Scope="RecursiveAll" />is used to load data from folders situated inside the lists.
Always remember, this thumb rule while requesting any data from the server
"Request only those data which is really required"