In this tutorial, I will explain how to work with the CAML query builder for SharePoint. This tool will help you build CAML queries to efficiently query lists and libraries.
We will learn how to download and install the CAML query builder for SharePoint, as well as how to utilize it within SharePoint.
Before understanding the CAML query builder, let us first understand what CAML is in SharePoint.
What is CAML in SharePoint?
CAML, or Collaborative Application Markup Language, is an XML-based language used in SharePoint to query and manipulate data stored in lists and libraries. CAML queries are essential for retrieving specific items, filtering data, and performing batch operations within SharePoint.
Key Features of CAML:
- XML syntax for defining queries
- Supports filtering, sorting, and grouping data
- Used in SharePoint REST API, CSOM, and server-side code
While CAML is powerful, writing queries by hand can be complex and error-prone, especially for those new to XML or SharePoint development. Common challenges include:
- Remembering the correct XML structure and syntax
- Handling nested queries for complex filtering
- Debugging and testing queries efficiently
Check out Create a Folder in SharePoint using REST API
CAML Query Builder in SharePoint
CAML, also known as Collaborative Application Markup Language, is an XML-based language for querying and updating SharePoint objects, such as lists and libraries.
A CAML Query Builder is a tool that provides a user-friendly interface for constructing CAML queries without writing XML manually. These tools are invaluable for both beginners and experienced SharePoint developers, as they help reduce errors and speed up the development process.
Benefits of Using a CAML Query Builder:
- Visual interface for building queries
- Real-time preview and validation
- Easy testing against SharePoint lists
- Export and reuse queries in your projects
Below is a simple syntax of the CAML query in SharePoint:
<Query>
<Where>
<Eq>
<FieldRef Name="FieldName" />
<Value Type="DataType">Value</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name="FieldName" />
<FieldRef Name="FieldName" />
</OrderBy>
</Query>Here, we can use various other operators like the below:
| Comparison Operators | General Meaning |
| Eq | = |
| Gt | > |
| Lt | < |
| Geq | >= |
| Leq | <= |
| Neq | <> |
| Contains | Like |
| IsNull | Null |
| IsNotNull | NotNull |
| BeginsWith | Beginning with the word |
| DateRangesOverlap | Compare the dates in a recurring event with a specified DateTime value to determine whether they overlap |
Rather than writing the query manually to query the SharePoint list, we can use a free tool known as the CAML Query Builder to generate the SharePoint CAML query for us.
Check out SharePoint REST API CRUD Operations [With Examples]
Download & Install CAML Query Builder in SharePoint
SharePoint caml query builder is a great tool to create and test CAML queries in SharePoint. This will work with both on-premise as well as SharePoint Online. You should have Microsoft .NET Framework 4.5 installed in your machine else it will not work.
First, Download the Tool from this URL and then install it. You can download “U2U Caml Query Builder for SharePoint 2013 (Standalone Edition)”.
The U2U Caml Query Builder for SharePoint will help us to query SharePoint list. Internally, this tool utilizes the SharePoint client object model code to remotely connect to SharePoint sites.
How to Use CAML Query Builder
Now, we will see how to use caml query builder to connect to SharePoint On-premises as well as SharePoint Online sites.
Once installation is over, when you open the tool, it will open the Connect dialog box, through which you will be able to connect to your on-premise as well as your online environment. See Fig below:

Here first, I gave my on-premise site URL, and when I connect it, it displays me all the lists and libraries presented in the SharePoint site like below:

Similarly, you can also connect to a SharePoint Online site. You must provide the username and password when connecting to an online site. And then the URL.
Enter the URL like https://<tenantname>.sharepoint.com/. If you add /SitePages/Home.aspx, it will throw an error. See fig below:

Here is my SharePoint Online, I have a list name as TestList and want to build the query for that SharePoint list.
Read Get SharePoint List Items using REST API
Build a CAML Query using the CAML Query Builder
Now, we will see how to build our CAML query using CAML query builder.
Now select the SharePoint Online List and then New query -> Query with View Fields as shown in the fig below

This will create two tabs: one is Query, and another one is View Fields. In the View Fields tab, you can select the Columns which are you want to query using the calm query builder like the one below:

Any time you can run the caml query and can see the results. It will also generate the CSOM Code and Server-side code for this which you see from the corresponding tabs.
Now, let us go to the Query tab and add some filter criteria to the query.
Here, I added a Filter that If Title Contains Items and then added Title equals Sharepoint item-1. You can add the Or or And condition by clicking on the Filter drop-down.
1. Add Order By in CAML Query
Similarly, If you want to add one Order by then you can click on the Add order by element button and then select the Column and the condition whether Ascending or Descending.
Then, it will generate the CAML query for you in the Editor box.

If you want to use the same query in a CSOM code, then you can write like below:
using (ClientContext ctx = new ClientContext())
{
Web web = ctx.Web;
List list = web.Lists.GetById(new Guid("5c42def2-bd2c-4df6-bcca-359351944cd2"));
var q = new CamlQuery() { ViewXml = "<View><Query><Where><Or><Contains><FieldRef Name='Title' /><Value Type='Text'>Items</Value></Contains><Eq><FieldRef Name='Title' /><Value Type='Text'>Sharepoint item-1</Value></Eq></Or></Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query><ViewFields><FieldRef Name='ID' /><FieldRef Name='First_x0020_Name' /><FieldRef Name='LinkTitle' /></ViewFields><QueryOptions /></View>"};
var r = list.GetItems(q);
ctx.Load(r);
ctx.ExecuteQuery();
}2. CAML Query Filter by Date Range
Let us see, how to use CAML based on the created date range in SharePoint. How to use caml query between two dates in SharePoint.
Recently I was working on reporting using the JavaScript client object model in SharePoint. Here, I need to retrieve records from a SharePoint list that were created between the current date and the specified date.
So I have written the query in the below format where startDate is the created start date, and endDate is the created end date. And also I have included IncludeTimeValue=’FALSE’, so that it will not consider the time part in the created date.
var startDate="2025-06-01T00:00:01Z";
var endDate="2025-30-04T00:00:01Z";
query = "<View Scope='RecursiveAll'><Query><Where><And><Geq><FieldRef Name='Created'/><Value Type='DateTime' IncludeTimeValue='FALSE'>"+startDate+ "</Value></Geq><Leq><FieldRef Name='Created'/><Value Type='DateTime' IncludeTimeValue='FALSE'>"+ endDate + "</Value></Leq></And></Where></Query></View>";When I run this query, it did not give me the result. After doing some research, I found that I gave the incorrect date format.
I had given the date format as “yyyy-dd-mmT00:00:01Z“. And it was the reason the filter was not working. When I changed the format to “yyyy-mm-ddT00:00:01Z” the filter started working. So my startDate and endDate will be like below:
var startDate="2015-06-01T00:00:01Z";
var endDate="2015-06-30T00:00:01Z";This is a very silly issue, but just want to share because if you ever face this kind of issue, you may check the date format. It will surely save you time.
Read SharePoint Get Current User ID, Name, Email, Display Name Programmatically using JavaScript
3. CAML Query for Boolean field for SharePoint
Let us see how to use CAML query for boolean field while working with client-side object model (csom) in SharePoint.
We had one SharePoint Online document library where we added one field as “IsCopied” which is of type Boolean. We wanted to query from the document library based on True/False. So, we wrote the query below:
var q = new CamlQuery() {<View><Query><Where><And><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + docTitle + "</Value></Eq><Eq><FieldRef Name='IsCopied' /><Value Type='Boolean'>TRUE</Value></Eq></And></Where></Query></View> }But it did not return the result for us. We thought it will return results where IsCopied is TRUE.
Actually, the Boolean field in SharePoint works in 1 (TRUE) and o (FALSE).
So we have to modify the code like below:
4. SharePoint CAML Query Boolean Field (For True Condition)
First, we will see how to use caml query in SharePoint for the boolean field for the true condition.
var q = new CamlQuery() {<View><Query><Where><And><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + docTitle + "</Value></Eq><Eq><FieldRef Name='IsCopied' /><Value Type='Boolean'>1</Value></Eq></And></Where></Query></View> }5. SharePoint CAML Query Boolean Field (For False Condition)
Here, we will see how to use the caml query in SharePoint for a boolean field for a false condition.
var q = new CamlQuery() {<View><Query><Where><And><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + docTitle + "</Value></Eq><Eq><FieldRef Name='IsCopied' /><Value Type='Boolean'>0</Value></Eq></And></Where></Query></View> }Now if you will query it will return the result correctly.
6. SharePoint CAML Query Boolean Field (Other Approach)
Instead of writing Type=’Boolean’, we can change it to Type=’Bool’, and then the query will work fine.
var q = new CamlQuery() {<View><Query><Where><And><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + docTitle + "</Value></Eq><Eq><FieldRef Name='IsCopied' /><Value Type='Bool'>True</Value></Eq></And></Where></Query></View> }Here I have shown how to use SharePoint CAML query a boolean field.
7. Filter CAML Query by List Item ID in SharePoint Online
Let us see how to retrieve list items from SharePoint based on ID. We will see how to filter the CAML query by list item ID in SharePoint.
<Query><Where><Eq><FieldRef Name="ID" /><Value Type="Counter ">' + ID + '</Value></Eq></Where></Query>8. Get Tasks Assigned To A User Or Current User Groups In SharePoint Using Caml Query
Here is the CAML query:
<View Name=……
<Query>
<Where>
<Or>
<Membership Type="CurrentUserGroups">
<FieldRef Name="AssignedTo" />
</Membership>
<Eq>
<FieldRef Name="AssignedTo" />
<Value Type="Integer">
<UserID Type="Integer"/>
</Value>
</Eq>
</Or>
</Where>
</Query>This is how we can assign a task to a user or a current user group in SharePoint using a CAML query.
9. SharePoint CAML Query Order by Example
Let us see how to use SharePoint CAML Query Order by in SharePoint. In this example, we will use a CAML Query with an ‘order by’ condition for a dropdown column in SharePoint.
When I was working with a SharePoint list having a dropdown column with values from 1 to 13.
I want to filter data order by the dropdown column. But when we use a dropdown column directly in a CAML query, it will not filter in the same order as it will consider 1, 10, 11, 12, 13, 2,3,4.. in this order.
For such a type of requirement, just create one more calculated column as shown below:

Then add this column and use this column in order by instead of the dropdown column. This will solve the problem.
Check out Get Current User using SharePoint Rest API
CAML Query Helper in SharePoint – Download, Install, and Use
Now, let us see how to download and install SharePoint CAML Query Helper. Additionally, we will explore how to utilize the SharePoint CAML Query Helper in SharePoint. I will discuss how to connect to the SharePoint Online site from the CAML query helper.
The SharePoint CAML helper tool helps build and test SharePoint CAML queries in both SharePoint on-premises and SharePoint Online.
Another feature of the SharePoint CAML query helper tool is that you can export field details and query results in CSV.
Download and Install SharePoint CAML Query Helper
Let us first download and install the SharePoint CAML query helper on the laptop.
Once you download and unzip, you will see two folders. In one folder as the name suggest a setup for MOSS 2007 and SP2010. Another folder contains the extension for SP2013. Open the SP2013 folder and double-click on SPCAMLQueryHelper2013.exe.
This will open the dialog box and ask you how to connect to the SharePoint site. You can connect by using the SharePoint object model (in this case, the tool needs to be installed on the server where SharePoint has been installed).
Connect to the SharePoint on-premises site from the CAML query helper
Now, we will first connect to the SharePoint site from the CAML query helper. Select Use SharePoint Object Model and click on SUBMIT.

Then it will ask you to give the Site URL, enter the URL, and click on Load. This will load all your lists and SharePoint Document libraries. Then you can double-click on a particular list, and it will load the details of the columns in the List Info tab. You can also get more information on the list using the MORE LIST DETAIL button, as shown in the figure below:

Connect to SharePoint Online Site from CAML Query Helper
Reload the tool, and this time, choose the “Use Web Services (Office 365)” option, then enter the Username and password you use to connect to the SharePoint Online site, as shown below. Here we will connect to a SharePoint Online from the SharePoint CAML helper.

Then, in the Next screen, give the Site URL and click on LOAD. It will load all the lists and Libraries from the SharePoint Online site.

Now, double-click on the particular list for which you want to write the query. This will load the list information in the List Info tab. You can see more details about the list by clicking on the “MORE LIST DETAIL” button. Apart from this, you can also export all the List Information by clicking on the EXPORT button.

Build a CAML Query using SharePoint CAML Query Helper
To write the query, click on the Query Helper tool. This provides three tabs: Query, View Fields, and View Attributes.
From the Fields box, you can drag and drop to the Query text box. In the Row Limit box, enter the value (Row limit). Click on the Search button to search for the query.

Then copy the code by clicking on the Copy Code button, which will generate the CSOM code, which will look like below:
string sQuery = @”<Query><OrderBy><FieldRef Name=””Modified”” Ascending=””FALSE””></FieldRef></OrderBy><Where> <BeginsWith><FieldRef Name=””Title””></FieldRef><Value Type=””Text””>item</Value></BeginsWith></Where></Query>”;
string sViewFields = @”<FieldRef Name=””Title”” /><FieldRef Name=””First_x0020_Name”” />”;
string sViewAttrs = @”Scope=””Recursive”””;
uint iRowLimit = 100;
var oQuery = new SPQuery();
oQuery.Query = sQuery;
oQuery.ViewFields = sViewFields;
oQuery.ViewAttributes = sViewAttrs;
oQuery.RowLimit = iRowLimit;
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach (SPListItem oListItem in collListItems)
{
}This is how to download, install, and use CAML Query helper for SharePoint.
Conclusion
In this tutorial, I have explained how to download and install U2U CAML Query Builder for SharePoint. How can we use the CAML query builder in SharePoint? Additionally, we explored how to utilize the CAML query builder to query the SharePoint list. This is how to use the SharePoint CAML Query builder.
You may also like the following tutorials:
- Filter an Array by Date in Power Automate
- Insert Column and Row into Excel Worksheet using Power Automate Desktop
- Extract Email from SharePoint Person or Group Field using JSON
- SharePoint List View Formatting by JSON Using Lookup Value

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.
Bijay …Bery good
Thank you so much for the sharing!