When LINQ was introduced into SharePoint 2010 it seamed like the way to go. But more and more we see that LINQ can have a performance impact. Now we see that CAML gains on importance again but it remains an exotic language that not everybody wants to learn. Therefore tools like the new CAML Designer can come in handy.
How to Troubleshoot Apps for the Modern Connected Worker
Karine bosch andy-van_steenbergen-caml-spsbe12
1. CAML is NOT dead!
Andy Van Steenbergen
Karine Bosch
SharePoint MVP
2. A big thanks to our sponsors
Platinum Sponsors
Gold Premium Sponsors Venue Sponsor
Gold Sponsors
3. About Us
• Karine Bosch
• SharePoint MVP since 2009
• Technical assistent of Patrick Tisseghem till September 2008
• Developer of the U2U CAML Builder
• Technical Lead SharePoint Competence Center @ ING
• Andy Van Steenbergen
• SharePoint consultant @ Ordina
• Vice-president BIWUG
4. Agenda
• What is CAML?
• CAML Basics
• CAML Deep Dive
• The new CAML Designer
5. What is CAML?
• Collaborative Application Markup Language
• XML-based query language
• Introduced in SharePoint 2001
• SharePoint 2010: LINQ to SharePoint
6. The Basics
• Ordery By
• Where
• ViewFields
• Query options
7. Order By Clause
• To sort list items
• In ascending order
<OrderBy>
<FieldRef Name=“Title” />
</OrderBy>
• In descending order
<OrderBy>
<FieldRef Name=“Title” Ascending=“False” />
</OrderBy>
• On more than 1 field
<OrderBy>
<FieldRef Name=“Title” />
<FieldRef Name=“LastName” Ascending=“False”/>
</OrderBy>
8. Where Clause
• Operators
• IsNull - IsNotNull
• Eq – Neq
• Geq – Gt – Leq – Lt
• BeginsWith
• Contains
• Includes
• In
• Example of a simple syntax:
<Where>
<Eq>
<FieldRef Name=“LastName” />
<Value Type=“Text”>Van Steenbergen</Value>
</Eq>
</Where>
9. Where Clause
• More than one criterium
• Nested XML
• And / Or operators
• Example of a nested syntax
<Where>
<Or>
<Eq>
<FieldRef Name=“LastName” />
<Value Type=“Text”>Van Steenbergen</Value>
</Eq>
<Eq>
<FieldRef Name=“LastName” />
<Value Type=“Text”>Bosch</Value>
</Eq>
</Or>
</Where>
10. Where Clause
• Example of a complex syntax
<Where>
<Or>
<Or>
<Eq>
<FieldRef Name=“LastName” />
<Value Type=“Text”>Van Steenbergen</Value>
</Eq>
<Eq>
<FieldRef Name=“LastName” />
<Value Type=“Text”>Bosch</Value>
</Eq>
</Or>
<Gt>
<FieldRef Name=“DownloadStart” />
<Value Type=“DateTime”>2012-04-28T00:00:00Z</Value>
</Gt>
</Or>
</Where>
11. Where Clause for DateTime fields
• DateTime Fields
• Query on date only
<Where>
<Gt>
<FieldRef Name=“DownloadStart” />
<Value Type=“DateTime”>2012-04-28T00:00:00Z</Value>
</Gt>
</Where>
• Query on date and time value
<Where>
<Gt>
<FieldRef Name=“DownloadStart” IncludeTimeValue=“True”/>
<Value Type=“DateTime”>2012-04-28T00:00:00Z</Value>
</Gt>
</Where>
12. Where Clause for Lookup fields
• Lookup fields
• Query on lookup value
<Where>
<Eq>
<FieldRef Name=“Country” />
<Value Type=“Lookup”>Belgie</Value>
</Eq>
</Where>
• Query on ID
<Where>
<Eq>
<FieldRef Name=“Country” LookupId=„True‟/>
<Value Type=“Integer”>15</Value>
</Eq>
</Where>
13. ViewFields Clause
• Restrict the number of fields returned
• No ViewFields clause
• Fields of default view are returned
<ViewFields>
<FieldRef Name=“LastName” />
<FieldRef Name=“FirstName” />
</ViewFields>
16. Query Options and the SharePoint Object Models
• Since SharePoint 2003
• Server Object Model
• Lists.asmx web Service
• Since SharePoint 2010
• .NET Client Object Model
• Silverlight Client Object Model
• JavaScript Client Object Model