SharePoint Developer Productivity Tip #3 – Easy CAML Queries

Previously, I wrote about CAML queries and the CAML Query Builder. I no longer use this tool. This is not because of any lack in the tool but rather a desire to simplify my development environment – a shift away from many specialty tools to a few generalized ones. Chief among these is SharePoint Manager 2007. In the previous productivity tip, I talked about using SPM to extract site columns for features (you can do something similar for content types with a bit more effort). This one is about CAML queries.

To get the syntax for a CAML query, I start by creating a view of the list that has the same structure as the ultimate target of the query. For example, I have a calendar, and I’d like to create a query of my upcoming (and sorely needed) vacations. I start by creating a new Calendar list to act as a prototype. Next, I create a new view with the desired set of fields and whatever sort, filter, and grouping I desire.

Once I have the view, deriving the CAML query from it with SPM is easy. I simply navigate to the view and copy the query and ViewFields from the Schema XML tab!

 

Author: Doug Ware