Taxonomy Field Type in Camlex

Oct 15, 2010 at 6:09 PM

Hi,How can i write following query with Camlex.

Please advise

<Query>
   <Where>
      <Eq>
         <FieldRef Name='AreaDirectory' />
         <Value Type='TaxonomyFieldTypeMulti'>XYZ</Value>
      </Eq>
   </Where>
</Query>

Developer
Oct 18, 2010 at 6:25 PM

Hi, ronakce!

Simply speaking - right now you can't.

Camlex project was developed for WSS 3.0 / MOSS 2007, while taxonomies have being adopted only in version SharePoint 2010.

Sure we have a plan to migrate Camlex project to SharePoint 2010 - Camlex 2010, but it will happens only after some time.

Coordinator
Oct 18, 2010 at 6:32 PM

hello

Camlex.NET was developed for Sharepoint 2007 version so currently it has no additional features which came with Sharepoint 2010 (including TaxonomyField). Although it is possible to use Camlex.NET in Sharepoint 2010 - there will no new features available only in 2010 version. We plan support for Sharepoint 2010 in the future. But currently you can use one of the existing extensibility points - ToCaml() method which will return array of XElement[] and you will be able to fix them using linq 2 xml:

// get query as array of XElements
var query = Camlex.Query().Where(x => (string)x["AreaDirectory"] == "XYZ").ToCaml(false);
// fix type manually using linq 2 xml
query[0].Elements().ElementAt(0).Elements().ElementAt(1).SetAttributeValue("Type", "TaxonomyFieldTypeMulti");

Console.WriteLine(query[0].ToString());

As result you will have the following CAML:

<Where>
  <Eq>
    <FieldRef Name="AreaDirectory" />
    <Value Type="TaxonomyFieldTypeMulti">XYZ</Value>
  </Eq>
</Where>

Of course it is not so elegant, but it will work. You can see more about ToCaml() method here.