Click here to Skip to main content
15,867,453 members
Articles / Productivity Apps and Services / Sharepoint
Article

CAML Query Builder

Rate me:
Please Sign up or sign in to vote.
4.89/5 (9 votes)
12 Sep 2012CPOL4 min read 192.5K   15   8
The SharePoint 2010 free tool CAML Query Builder.

Free Tool 2 - CAML Query Builder

In this article we can explore the SharePoint 2010 free tool CAML Query Builder.

What is CAML?

CAML represents Collaborative Markup Language which is an XML based language for querying and updating SharePoint objects.

What are the advantages of this tool?

The following are the advantages of using this tool:

  1. As CAML is non-typed and error prone during development, the CAML Query Builder provides advantage of writing and validating CAML queries.
  2. An Intuitive User Interface is provided by the application for more easier query building.
  3. Above all the tool is free.

Download

You can download the tool from the following location: http://www.u2u.be/res/tools/camlquerybuilder.aspx. Please make sure you download the 2007 version which works well with SharePoint 2010.

Image 1

Download the tool and extract the zip file to a temporary folder. Execute the setup.exe inside it and follow the wizard to install the tool.

Note: The SharePoint binaries are required for working with this tool.

Starting with the tool

After the installation, execute the tool from the Start menu or Desktop. The tool is available on Start menu > U2U > CAML Builder > CAML Builder, as shown below.

Image 2

On execution you can see the following screen.

Image 3

Enter the following details as shown above:

  • URL of the site
  • Connect through SharePoint Web Services
  • User Credentials

After entering the details, click the Connect button.

Note: As the tool is for SharePoint 2007, the Connect via Object Model option cannot be used.

Inside the tool

On connecting successfully, you will get the following screen.

Image 4

You can see that the above screen displays your existing Lists and Libraries. Additionally it displays the Lists and Libraries which are hidden in the Quick Launch tool.

Create a Contacts List

To start with, create a Contacts list of Contacts template inside your SharePoint site. Insert the following test data into it and refresh the CAML Query Builder Tool.

Image 5

Building your first CAML query

Now we can try building our first query using the CAML Query Builder Tool. Here we are trying to find the list items for which First Name contains ‘1’.

Step 1: Start the New Query pane.

Right click on the Contacts list from the left side pane and choose the New Query menu.

Image 6

You can also use the New Query button from the tool bar.

Step 2: Specify the Column Parameters.

From the pane on the right side, choose the Filter Column > First Name using the second drop down list as shown below.

Image 7

Now choose the option Contains from the third drop down list. Enter the text 1 in the textbox.

Note: Following are the dropdownlists shown and their purpose:

  • The first dropdownlist contains the options Filter, And, Or.
  • The second drop down list contains the Column Names of the selected list.
  • The third drop down list contains the conditions like Equal, Not Equal, Contains etc.

Step 3: View the CAML query.

On performing the above steps you can see that the CAML wuery is generated for the above condition. You can see the CAML query in the bottom pane as shown below.

Image 8

Step 4: Executing the CAML query.

Now you are ready with the CAML query but it is not tested yet. For testing the query, use the Execute query button from the top toolbar as shown below.

Image 9

You should be getting the results as shown above.

Now you are ready with the CAML query which is tested and can be copied to your application.

Step 5: Adding an OR condition.

Now we can play a little bit more by adding an OR Condition to the list of all the Contacts items which contain ‘1’ or ‘2’ in the First Name column.

Image 10

For achieving this, select the Or option from the Filter drop down list.

You can see that a new filter row is added to the query pane. Enter the new parameters in the new row as shown below.

Image 11

Step 6: Execute the new query.

Image 12

Now you can try executing the above query and this time the result should show both the records from the Contacts list.

Add Order By element

Now we can try using the Add Order By element button. This option allows us to add the Order By CAML tags. You can specify a column and the order (ascending or descending).

Create a new query and click on the Add Order by element button from the toolbar. Choose the ID column and order as Descending.

Image 13

On executing the query, you can see the following result.

Image 14

Please note that the items are now shown in the descending order of ID values.

Multiple Order By columns

We can have multiple Order By columns. Use the same button again to add a new Order By CAML tag as shown below.

Image 15

This time we have two Order by columns. The Created By column is sorted in an Ascending fashion.

More Options in the CAML Query Builder Tool

You can explore more options in building CAML queries using the tool like:

  1. Creating queries for Date columns
  2. Trying with AND operator
  3. Filtering with Equal To, Lower Than, Greater Than conditions
  4. Using the Copy Query button to copy the query to clipboard

References

Summary

In this article we have explored the tool CAML Query Builder. In real life scenarios, this tool should give time, cost, and efficiency advantages.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Jean Paul is a Microsoft MVP and Architect with 12+ years of experience. He is very much passionate in programming and his core skills are SharePoint, ASP.NET & C#.

In the academic side he do hold a BS in Computer Science & MBA. In the certification side he holds MCPD & MCTS spanning from .Net Fundamentals to SQL Server.

Most of the free time he will be doing technical activities like researching solutions, writing articles, resolving forum problems etc. He believes quality & satisfaction goes hand in hand.

You can find some of his work over here. He blogs at http://jeanpaulva.com

Comments and Discussions

 
QuestionRecursive Pin
Member 1248151814-May-16 7:14
Member 1248151814-May-16 7:14 
How to add recursive all in this query builder. I have to search items inside folders.
Questionmy vote 0f 4 Pin
vanita khatnani12-Jul-13 17:52
professionalvanita khatnani12-Jul-13 17:52 
QuestionCAML query tool link Pin
Member 1010437915-Jun-13 12:18
Member 1010437915-Jun-13 12:18 
Questiongood article but... Pin
Andrey Babushkin23-May-13 0:06
professionalAndrey Babushkin23-May-13 0:06 
Generalnice article Pin
tanuja kothur11-May-13 9:50
tanuja kothur11-May-13 9:50 
GeneralRe: nice article Pin
Jean Paul V.A11-May-13 9:59
Jean Paul V.A11-May-13 9:59 
GeneralMy vote of 5 Pin
Pradeep Kurmi11-Apr-13 19:15
Pradeep Kurmi11-Apr-13 19:15 
GeneralRe: My vote of 5 Pin
Jean Paul V.A11-May-13 9:59
Jean Paul V.A11-May-13 9:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.