CAML Generators

Stramit’s SharePoint Blog

While working with SharePoint it is often require to Query items using CAML.  I thouhg it would be nice to share the tools to load CAML Dynamicaly.  So here is the tool.  The latest one is for SharePoint Server 2007.  the Download links are also given.

Here the 2007 version !
CapCamlViewer1-2007.jpg
Feature
————

  • Use only Web services from SharePoint 2007
  • use current or custom credentials
  • list of the different list and views (hidden or not) of the selected site
  • auto capture of the CAML source of each component : list / View / Fields / Query
  • get a full CAML list of each column of a list
  • the cAML is view by 3 ways : string, formated indexed XML string and treeview style
  • each CAML code can generate a stringbuilder version in VB or C#
  • the query can be directly execute and test in a result tab : gridview / xml string or Treeview Style

Here’s some screencap
Install process :
——————
You just need the .Net framework 2 🙂

Download

CAML for SharePoint 2.0

Patrick Tisseghem’s Blog [MVP SharePoint]

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

Download

Enjoy

Jerry

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s