Skip to main content

Patrick Tisseghem's Blog [MVP SharePoint]

Go Search
U2U Blog Center
U2U website
  

The Happy SharePoint Traveller

U2U Blog Center > Patrick Tisseghem's Blog [MVP SharePoint] > Posts > CAML Query Builder V2
CAML Query Builder V2

Querying Data with the CAML Query Builder V2

It has been a couple of months now since we have released the first version of the CAML Query Builder. Thanks a lot for the very positive feedback we have received from you all. Do remember that this is side-project of our CAML girl and not a fully commercial product. So we do our best to get everything working and support you with any questions but sometimes you have to be patient. Sorry for that.

Today, you can download version 2 giving you the following additional features on top of what you find in version 1. You can learn about the v1 features by reading my first posting on the CAML Query Builder tool over here.

So, what is new in v2?

  • You can now choose whether you work in object model or in Web services mode. It means that you now can use the app on the SharePoint machine itself and on a client accessing the SharePoint content via the Web services.
  • When working with the object model, you can only query for content. If you opt for Web services mode, you can query but also now update content in a SharePoint list using CAML.
  • You now also have the possibility to make use of parameters and give these parameters a value at runtime when using the CAML Server Helper to execute the saved CAML query string.

The new version is downloadable using the following link: http://www.u2u.info/SharePoint/U2U%20Community%20Tools/CamlCreatorV2.zip.

Update: Always go the library itself to download the latest version available.

And don't forget that you find on http://www.u2u.info/SharePoint some other goodies to play with.

Now before you start looking at the tutor, read my previous posting and the article on using the SmartPart.

Just like before, I will illustrate the use of the CAML Query Builder and the new features using a small example. I will make use of the same SharePoint list as before showing the AdventureWorks products.

 

U2UCamlCreator.exe starts the query builder application. You can set the credentials and also now choose the mode you want to work in.

Getting only the fields you need

V1 of the CAML Query Builder retrieved always all of the fields from the list. This version here allows you to select the fields you want to get returned from the SharePoint site. Just right-click on the list you want to work with in the treeview. Note that this only works now for the Web services mode.

Using the View Fields tab and the listboxes you can then define the fields you want to work with. Clicking on the Query tab allows you to define the query then as with the V1 version.

And of course, you can test it again.

Dynamic Parameters

If you want to have the filtering value dynamic, you can now insert in the value field the name of a parameter enclosed between []. If you follow my steps, you can click now in the treeview displaying the results of your actions on the Model node.

The name of the parameter is free, just use the brackets so that the CAML girl knows that you want to go dynamic.

In the test pane, you can then give a value to this parameter. Move to the second tab and click parameters. The Get Parameters button can be used to fill up the datagrid with your parameters.

And of course, you can test again your query.

Executing the Query in your Code

The CAML builder allows you to store the query as a file. Just use the File | Save File menu item. Once it is saved, we can use the server component of the CAML builder to have this query executed within our code. Just like the previous tutor, I have a small ASP.NET user control that I am going to host in the smartpart. Except now I have a text box where we can enter a search string.

Follow the steps discussed in the previous tutor to set the reference and then create an object of the CAML Helper.
You need a reference to the following assemblies:

  • U2U.SharePoint.CAML.dll
  • U2U.SharePoint.CAML.Server.dll

Since we are having one parameter, you need to first create an array of CAMLParameter objects and add to it one CAMLParameter object.
Just like before, the ExecuteQuery method returns you a ADO.NET DataTable you can immediately bind to your DataGrid.

U2U.SharePoint.CAML.Server.CAMLHelper helper =
     new U2U.SharePoint.CAML.Server.CAMLHelper
       (Server.MapPath("~/UserControls/products_v2.caml"));
U2U.SharePoint.CAML.CamlParameter[] pars = new U2U.SharePoint.CAML.CamlParameter[1];
pars[0] = new U2U.SharePoint.CAML.CamlParameter("Model",TextBox1.Text);
DataTable dt = helper.ExecuteQuery(pars);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();

The result can be displayed in the Web part:

 

You can also use the CAML Query Builder now to construct your query string to do update/new/delete operations via CAML. I will give a sample and some steps to follow hopefully later this week. It is getting late here in Oslo and tomorrow is again working day :-). 2 days in Oslo and then going all the way from Northern Europe to South-Africa for 2 more days on Portals.

Have fun with it! You can send questions, feedback, bug reports either to me (patrick@u2u.be) or directly to our CAML girl (karine@u2u.be).

Comments

assembly generation failed error

I followed all the steps mentioned in the article. But when it came to building the project, It threw the following error -

Assembly generation failed -- Referenced assembly 'U2U.SharePoint.CAML.Server' does not have a strong name


Any idea why?

Thanks
Sourav Nayyar
souravnayyar@rediffmail.com
at 3/05/2007 14:25

caml query builder

send-> download a copy is not authorized in your sharepoint site
at 18/09/2007 12:54

caml query builder

send-> download a copy is not authorized in your sharepoint site
at 18/09/2007 12:54

Re: CAML Query Builder V2

this is a blog isn't it  very nice
at 25/09/2007 11:49

caml query builder

for strong name  u have to project->properties->click on signing->click sign in ->give strog name key after that build the project or deploy on sharepoinr site
at 12/10/2007 17:37

Microsfoft.Sharepoint.dll

First of all can I just say congratulations Patrick on an excellent CAML Creator tool and a relevant clear easy to read and very informative blog. very helpful for junior develpors like me who are dipping my toe into Sharepoint manipulation for the first time.

Secondly the tutorials also look interesting, when I get my new machine and will then be able to get them to work.

On a slightly lesser note, can I just add that seeing as I presently operate on xp which clashes with WSS 3.0 installation, meaning Microsoft.Sharepoint.dll and development with is out of bounds for me for the next week at least, I was slightly disappointed to find out that we required this as well as the web services for the tutorial to work.

This frustration I might add is onlytemporary, but could you possibly make this clear in future releases that it is not a <b>pure</b> web services sourced sharepoint development ?

Thanks though. Exellent site.

 
at 13/02/2008 18:57

No Access

When I click on http://www.u2u.info/SharePoint/U2U%20Community%20Tools/CamlCreatorV2.zip.
 I get an HTTP 404 error. I was unable to download CamlCreatorv2.
at 7/03/2008 23:36

Download

CAML builder is now available as within this library http://www.u2u.info/SharePoint/U2U%20Community%20Tools/Forms/AllItems.aspx.

Patrick
Patrick Tisseghem at 9/03/2008 10:40

CAML Query builder

Thank - you. Excellent work!
at 28/03/2008 16:03

Invalid URL Parameter when running CAML

Hi everyOne!

Patrick: Thank you for making this tool available, it comes to good use ;)

When I run the following CAML:
----------
<Batch OnError='Continue'>
   <Method ID='1' Cmd='Update'>
      <Field Name='SaNumber'>sa01</Field>
      <Field Name='Project_x0020_Manager'>silf</Field>
   </Method>
</Batch>
----------
I get the following error:
----------
Invalid URL Parameter
The URL provided contains an invalid Command or Value. Please check the URL again.
----------
Using the same URL when querying the same list yields correct data.

With my current credentials I can do the update manually in the Web interface.

Any ideas what might be causing this???
Could this be a server config thing....

Best regards:
Finnur Eiríksson, Reykjavik Iceland
at 23/04/2008 14:09

Cannot download

When I follow the new link (http://www.u2u.info/SharePoint/U2U%20Community%20Tools/Forms/AllItems.aspx)
and try to download it asks me for a user name and password.  I'm unable to find out how to get a username and password.
at 17/06/2008 19:59

Great Tool

Thank you so much for this tool. Has saved my day a couple of times..
at 4/07/2008 8:28

Good Blog

Congrates for this nice blog which helped me  lot..........
   REGARDS
           NIRAJ(niraj.bagde@innovapoint.com)
at 12/08/2008 15:31

401 - Access Denied

All these links give a hardy '401 Unauthorized':

The new version is downloadable using the following link: http://www.u2u.info/SharePoint/U2U%20Community%20Tools/CamlCreatorV2.zip

Update: Always go the 'library itself' to download the latest version available.

And don't forget that you find on http://www.u2u.info/SharePoint some other goodies to play with.

Looks like a fun tool.
at 7/01/2009 17:02

401

Hi there, still getting a 401 when trying to access http://www.u2u.info/SharePoint
at 8/01/2009 13:20

Response to 401

at 13/01/2009 19:11

Error - Data at the root level is invalid. Line 1, position 1.

I would like to query data on a Sharepoint list by creating a web application using Visual Studio 2008 and U2U Sharepoint Server dll. 
I tried the code about and am getting the following error when trying to compile - Data at the root level is invalid. Line 1, position 1.
Any suggestion.
at 28/01/2009 15:47

Caml Query to access Dropdown data

Hello,
I am using a dropdown which has all the provinces. Now i want to write a caml Query which will show only the cities which are in that Province, in other drop down (City Drop down).
Data comes from 2 lists. The City List has Province and City.

Selecting Province1 in dropdown1 should list all Cities in that Province in Dropdown2.


  
at 17/02/2009 11:33

Hi.  Great Tool.

I am trying to create my first CAML using your tool.  I am trying to return from the Calendar list with all entries where the start date dis greater or equal to today.  I can't seem to do that as the CAML tool inserts the static date.  What I want is a dynamic date base on the today's date.  Thanks

===================
<ViewFields>
   <FieldRef Name='Title' />
</ViewFields>
<Query>
   <OrderBy>
      <FieldRef Name='EventDate' />
   </OrderBy>
   <Where>
      <Geq>
         <FieldRef Name='EventDate' />
         <Value Type='DateTime'>2009-02-25T00:00:00Z</Value>
      </Geq>
   </Where>
</Query>
at 25/02/2009 23:01

I got it

Please ignore my last email.  Figure it out... read you other posts
at 25/02/2009 23:13

Thanks a lot

This is a great tool...
at 8/03/2009 6:26

can't download it

The links you have in this post either don't work or ask for a username and pass.  Someone posted another link but that's to an older version.

Any ideas?
at 9/04/2009 23:59

Download it here ...

Seems (from the date at the top of the page) that this is a very old blog. In fact, the latest version of the CAML Query Builder is available here http://www.u2u.be/res/Tools/CamlQueryBuilder.aspx
at 18/04/2009 5:48

Latest CAML Querybuilder

Hi Guys,
             Can someone please help me with the link to  CAML query builder V2. All the above links point to the older version of CAML query builder. The link that pointed to V2 with "view fields" and "Query Options" features....is invalid. Other links ask for username and password.

Thanks in advance!

CHEERS!
at 21/05/2009 22:08
Captcha

Enter the code shown above: *

(Note: If you cannot read the numbers in the above
image, reload the page to generate a new one.)