<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>caml &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/caml/</link>
	<description>Feed of posts on WordPress.com tagged "caml"</description>
	<pubDate>Wed, 25 Nov 2009 05:09:13 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[CAML FileName]]></title>
<link>http://sladescross.wordpress.com/2009/10/19/caml-filename/</link>
<pubDate>Mon, 19 Oct 2009 17:50:13 +0000</pubDate>
<dc:creator>sladescross</dc:creator>
<guid>http://sladescross.wordpress.com/2009/10/19/caml-filename/</guid>
<description><![CDATA[&lt;OrderBy&gt;&lt;FieldRef Name=&#8217;LinkFilenameNoMenu&#8217; /&gt;&lt;/OrderBy&gt; &lt;Field Na]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>&#60;OrderBy&#62;&#60;FieldRef Name=&#8217;LinkFilenameNoMenu&#8217; /&#62;&#60;/OrderBy&#62;</p>
<p>&#60;Field Name=&#8217;FileRef&#8217;&#62;</p>
<p align="left">http://MyServer/MySite/MyDocs/Document1.doc</p>
<p>&#60;/Field&#62;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to use Case statement in RenderPattern of a Custom Field Type]]></title>
<link>http://sharepointinsight.wordpress.com/2009/10/14/how-to-use-case-statement-in-renderpattern-of-a-custom-field-type/</link>
<pubDate>Wed, 14 Oct 2009 22:19:34 +0000</pubDate>
<dc:creator>namwar</dc:creator>
<guid>http://sharepointinsight.wordpress.com/2009/10/14/how-to-use-case-statement-in-renderpattern-of-a-custom-field-type/</guid>
<description><![CDATA[While designing a custom field type, you may sometime need to render different HTML based on the val]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>While designing a custom field type, you may sometime need to render different HTML based on the value of field. For example, if you want to display Red,Amber, Green traffic light images to highlight High,Medium, Low value then you need to dynamically switch image url based  on the value of the field.</p>
<p>In CAML, you have Case structure to implement this switching logic. It works very much like the C# switch-case statement. Following is an example of RenderPattern of a custom field which display different images based on the value of the field.</p>
<pre class="brush: xml;">
&#60;RenderPattern Name=&#34;DisplayPattern&#34;&#62;
      &#60;Switch&#62;
        &#60;Expr&#62;
          &#60;Column /&#62;
        &#60;/Expr&#62;
        &#60;Case Value=&#34;1&#34; &#62;
          &#60;HTML&#62;&#60;![CDATA[&#60;img alt=&#34;Red&#34; src=&#34;/_layouts/IMAGES/ewr210m.gif&#34; /&#62;]]&#62;&#60;/HTML&#62;
         &#60;/Case&#62;
        &#60;Case Value=&#34;2&#34; &#62;
          &#60;HTML&#62;&#60;![CDATA[&#60;img alt=&#34;Amber&#34; src=&#34;/_layouts/IMAGES/ewr211m.gif&#34;]]&#62;&#60;/HTML&#62;
        &#60;/Case&#62;
        &#60;Case Value=&#34;3&#34; &#62;
          &#60;HTML&#62;&#60;![CDATA[&#60;img alt=&#34;Green&#34; src=&#34;/_layouts/IMAGES/ewr209m.gif&#34;]]&#62;&#60;/HTML&#62;
        &#60;/Case&#62;
        &#60;Default&#62;
            &#60;HTML&#62;&#60;![CDATA[&#60;span&#62;No Value&#60;/span&#62;]]&#62;&#60;/HTML&#62;
        &#60;/Default&#62;
      &#60;/Switch&#62;
    &#60;/RenderPattern&#62;
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Notepad++ 5.5.1]]></title>
<link>http://netvietnam.org/2009/10/09/notepad-5-5-1/</link>
<pubDate>Fri, 09 Oct 2009 12:15:09 +0000</pubDate>
<dc:creator>Nhân Mã</dc:creator>
<guid>http://netvietnam.org/2009/10/09/notepad-5-5-1/</guid>
<description><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></description>
<content:encoded><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></content:encoded>
</item>
<item>
<title><![CDATA[Working with sharepoint large lists]]></title>
<link>http://techyard.wordpress.com/2009/10/07/working-with-sharepoint-large-lists/</link>
<pubDate>Wed, 07 Oct 2009 15:27:45 +0000</pubDate>
<dc:creator>techyard</dc:creator>
<guid>http://techyard.wordpress.com/2009/10/07/working-with-sharepoint-large-lists/</guid>
<description><![CDATA[In a recent project, I had to get some information from the last sharepoint listitems inserted. I us]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In a recent project, I had to get some information from the last sharepoint listitems inserted. I used foreach. Of course it is a bad idea. When the list grew (thousand of listitems)&#8230;the program worked as fast as a drunken turtle. Ok&#8230; As I was saying the data I needed was from the last x items inserted. So I replaced the foreach with a simple for:<br />
count=10; (the last 10 items inserted)<br />
 for (int i = oList.Items.Count &#8211; count; i &#60; oList.Items.Count; i++)</p>
<p>I ran the program and saw that the improvement was not what I expected, so I made a testProject to measure the execution time, for the foreach block code and the code above (with the simple for);</p>
<p>DateTime startTime = DateTime.Now;</p>
<p>chunk of code (for or foreach iteration)</p>
<p> DateTime stopTime = DateTime.Now;<br />
 TimeSpan duration = stopTime &#8211; startTime;</p>
<p>For large lists the foreach statement took forever. The for statement took from 5 to 30 seconds for 4000 list items.<br />
The odd part was that in the for statement as I said before, i iterated through the last 10 items.<br />
So for 10 items I waited some good seconds.<br />
I googled for the truth and I found this interesting <a href="http://www.docstoc.com/docs/12105826/Working-with-large-lists-in-Office---Office-Online-Home-Page">article</a>.</p>
<p>So I found out the SPQuery is one of the best ways to work with large lists.</p>
<p> SPQuery query = new SPQuery(oList.Views[0]);<br />
<img src="http://techyard.wordpress.com/files/2009/10/comm.jpg" alt="Comm" title="Comm" width="450" height="37" class="aligncenter size-full wp-image-73" /><br />
            query.RowLimit = 10;<br />
SPListItemCollection filteredList = oList.GetItems(query);<br />
foreach (SPListItem item in filteredList)<br />
            {<br />
			Blabla;<br />
             }</p>
<p>I ordered the list Descending by their ID so i got the most recent 10 list items.<br />
I measured the execution time. At the first run it took 800 milliseconds for 4000 list items. The next executions took only from 15 to 30 milliseconds.<br />
I would say&#8230;it is at least a good improvement;<br />
An easier way to create CAML queries is with <a href="http://www.u2u.be/Res/Tools/CamlQueryBuilder.aspx"> U2U CAML Query Builder</a><br />
I tried to use CAML query to get the max ID directly but I didn`t succeed. If someone reads this&#8230;:P and knows how please leave a reply.<br />
Thank you,<br />
Dan Gheorghe</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Sharepoint - Schema Files]]></title>
<link>http://abstractspaces.wordpress.com/2009/10/07/sharepoint-schema-files/</link>
<pubDate>Wed, 07 Oct 2009 12:51:47 +0000</pubDate>
<dc:creator>sanghvinirav</dc:creator>
<guid>http://abstractspaces.wordpress.com/2009/10/07/sharepoint-schema-files/</guid>
<description><![CDATA[The following table describes other schema files that use CAML Core Schemas for data definition or H]]></description>
<content:encoded><![CDATA[The following table describes other schema files that use CAML Core Schemas for data definition or H]]></content:encoded>
</item>
<item>
<title><![CDATA[Sharepoint Retrieve List Item Using CAML And SPQuery]]></title>
<link>http://sladescross.wordpress.com/2009/10/06/sharepoint-retrieve-list-item-using-caml-and-spquery/</link>
<pubDate>Tue, 06 Oct 2009 08:32:40 +0000</pubDate>
<dc:creator>sladescross</dc:creator>
<guid>http://sladescross.wordpress.com/2009/10/06/sharepoint-retrieve-list-item-using-caml-and-spquery/</guid>
<description><![CDATA[http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-f]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list">http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list</a></p>
<p>If you need to retrieve items from a list when developing web parts, application pages or custom field types you can best use the <strong>SPQuery</strong>object from the SharePoint object model. This object is located in the <strong>Microsoft.SharePoint </strong>namespace of the <strong>Microsoft.SharePoint.dll</strong> located in the Global Assembly Cache.</p>
<p>Instantiate the object as follows:</p>
<pre>SPQuery qry = new SPQuery();</pre>
<p>The most important property is the <strong>Query</strong> property, which needs to be set to your CAML query:</p>
<pre>string camlquery = "&#60;OrderBy&#62;&#60;FieldRef Name='Country' /&#62;&#60;/OrderBy&#62;&#60;Where&#62;"
    + "&#60;Eq&#62;&#60;FieldRef Name='LastName' /&#62;&#60;Value Type='Text'&#62;Smith&#60;/Value&#62;&#60;/Eq&#62;"
    + &#60;/Where&#62;";
qry.Query = camlquery;</pre>
<p>At this point you can execute the query on your list:</p>
<pre>SPListItemCollection listItemsCollection = list.GetItems(qry);</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[CAML.NET IntelliSense for SharePoint]]></title>
<link>http://bhavtosh.wordpress.com/2009/10/05/caml-net-intellisense-for-sharepoint/</link>
<pubDate>Mon, 05 Oct 2009 13:03:58 +0000</pubDate>
<dc:creator>bhavtosh</dc:creator>
<guid>http://bhavtosh.wordpress.com/2009/10/05/caml-net-intellisense-for-sharepoint/</guid>
<description><![CDATA[CAML is being used a lot by sharepoint in order to provide lot of functionality and microsoft has do]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>CAML is being used a lot by sharepoint in order to provide lot of functionality and microsoft has done a good work here by providing an intellisense to make coding easier.</p>
<p>Check out more information <a href="CAML.NET IntelliSense for SharePoint" target="_blank">here</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Using Expression Trees and Lambda Expressions to perform CAML queries - Part 1]]></title>
<link>http://johanleino.wordpress.com/2009/09/21/using-expression-trees-and-lambda-expressions-to-perform-caml-queries-part-1/</link>
<pubDate>Mon, 21 Sep 2009 17:34:38 +0000</pubDate>
<dc:creator>Johan Leino</dc:creator>
<guid>http://johanleino.wordpress.com/2009/09/21/using-expression-trees-and-lambda-expressions-to-perform-caml-queries-part-1/</guid>
<description><![CDATA[I have a problem. I live for writing &#8220;good looking&#8221; and &#8220;easy to read&#8221; (main]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I have a problem.<br />
I live for writing &#8220;good looking&#8221; and &#8220;easy to read&#8221; (maintainable) code &#8220;despite&#8221; using SharePoint as a backend framework. That combination is sometimes not so easy though.<br />
Imagine this example of such an occasion:</p>
<p>I want to be able to write queries to execute in my C# project that uses SharePoint as the backend. <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx" target="_blank">SPSiteDataQuery</a> is the prefered option and such a query is constructed using <a href="http://en.wikipedia.org/wiki/Collaborative_Application_Markup_Language" target="_blank">CAML </a>(Collaborative Application Markup Language), a special form of query language used in SharePoint.<br />
The problem with CAML is that it is somewhat hard to understand and maintain. Imagine that I want to find all items that are of a certain type (in SharePoint a content type), i.e. a book in my backend system.</p>
<p>Before going further, here is a list of the other posts in the series:</p>
<ul>
<li><a href="http://johanleino.wordpress.com/2009/09/24/using-expression-trees-and-lambda-expressions-to-perform-caml-queries-%e2%80%93-part-2/" target="_blank">Using Expression Trees and Lambda Expressions to perform CAML queries – Part 2 </a></li>
</ul>
<p>Let´s continue&#8230;<br />
Normally you construct a sort of business layer (some might use a sort of <a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/10/08/the-repository-pattern.aspx">repository</a> in if you use  the ideas of <a href="http://en.wikipedia.org/wiki/Domain-driven_design">domain driven design DDD</a>) with a method that can take a string that is the CAML, something like this:</p>
<pre class="brush: csharp;">
public static IList&#60;SPListItem&#62; FindAll(string caml)...
</pre>
<p>When we call that method it looks something like this to find items of a certain content type:</p>
<pre class="brush: csharp;">
FindAll(&#34;&#60;Where&#62;&#60;BeginsWith&#62;&#60;FieldRef Name=\&#34;ContentTypeId\&#34; /&#62;&#60;Value Type=\&#34;Text\&#34;&#62;0x010101008103BAF1CBB541CB9F9A6DF623AEFEDD&#60;/Value&#62;&#60;/BeginsWith&#62;&#60;/Where&#62;&#34;)
</pre>
<p>That isn&#8217;t a pretty looking peace of code if you ask me, it´s a definite <a href="http://en.wikipedia.org/wiki/Code_smell">code smell</a>.<br />
Why?<br />
Well, first of all if you aren´t fluent in CAML you won´t have a chance of reading that and understanding it right away. Ok, so this example isn´t very hard but imagine that you had a more complex expression with a couple of ANDs and ORs in it.<br />
Some might say that we could encapsulate the CAML using some like <a href="http://www.johnholliday.net/post/2007/04/22/Write-Your-CAML-Queries-in-C-using-CAMLNET.aspx">CamlDotNet</a> to construct the query. That´s great, I would respond but the problem is still there though (that is just a more fancy way of constructing CAML). CAML is bad when you would like your code to be easy to read, maintainable, and expressive.</p>
<p>I have for a while looked at <a href="http://www.codeplex.com/LINQtoSharePoint">LinqToSharePoint</a> to solve this for me but I still had some problems with it. First of all I think it is too large for me, I only want to use something like LINQ (lambda expressions) to ask the questions and then translate them into CAML. <a href="http://www.codeplex.com/LINQtoSharePoint">LinqToSharePoint</a> is great (and probably will be even greater in 2010) but in this situation it doesn´t quite do the trick. The big advantage with LINQ (and <a href="http://msdn.microsoft.com/en-us/library/bb397951.aspx">Expression Trees</a>) is that it is a uniform (and easy to read) way to construct a filter (some might call that a query) over a collection of items.</p>
<p>So after reading up on Expression Tree parsing, here´s a list of some of the blog posts I have found:</p>
<ul>
<li><a href="http://blogs.msdn.com/mattwar/pages/linq-links.aspx">http://blogs.msdn.com/mattwar/pages/linq-links.aspx</a></li>
<li><a href="http://blogs.msdn.com/jomo_fisher/archive/2007/05/23/dealing-with-linq-s-immutable-expression-trees.aspx">http://blogs.msdn.com/jomo_fisher/archive/2007/05/23/dealing-with-linq-s-immutable-expression-trees.aspx</a></li>
<li><a href="http://community.bartdesmet.net/blogs/bart/archive/2008/09/14/who-ever-said-linq-predicates-need-to-be-boolean-valued.aspx">http://community.bartdesmet.net/blogs/bart/archive/2008/09/14/who-ever-said-linq-predicates-need-to-be-boolean-valued.aspx</a></li>
<li><a href="http://manfred-ramoser.blogspot.com/2009/04/linq-expression-tree.html">http://manfred-ramoser.blogspot.com/2009/04/linq-expression-tree.html</a></li>
</ul>
<p>…I started to construct my own parser, starting with the new method signature that will look like this (which now makes it possible for me to call this function with an expression):</p>
<pre class="brush: csharp;">
public static IList&#60;SharePointItem&#62; FindAll(Expression&#60;Func&#60;SharePointItem, bool&#62;&#62; expression)
</pre>
<p><strong>Note:</strong> SharePointItem is just a class that I have constructed to encapsulate some of the stuff I need to know about a SPListItem:</p>
<pre class="brush: csharp;">
    class SharePointItem
    {
        public string ContentTypeId { get; set; }
        public int ListItemId { get; set; }
        public Guid SiteId { get; set; }
        public Guid ListId { get; set; }
</pre>
<p>The <a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx" target="_blank">Func</a>&#60;SharePointItem, bool&#62; delegate encapsulates a method that will return a <strong>bool</strong> and will take a <strong>SharePointItem</strong> as an inputparameter.</p>
<p>The following lambda expression will meet that expectation:</p>
<pre class="brush: csharp;">
SPItem =&#62; SPItem.ContentTypeId.StartsWith(“0x010101008103BAF1CBB541CB9F9A6DF623AEFEDD”)
</pre>
<p> The lambda expression <strong>SPItem =&#62; SPItem.ContentTypeId.StartsWith(contentTypeId) </strong>is really just a fancy way of writing a method that looks like this :</p>
<pre class="brush: csharp;">
public static bool ContentTypeIs(SharePointItem item, string contentTypeId)
{
    return item.ContentTypeId.StartsWith(contentTypeId);
}
</pre>
<p>OK, so now I think I have removed the smell and the code is now again easy to read and maintain.<br />
The issue now is how do I translate an <a href="http://msdn.microsoft.com/en-us/library/bb397951.aspx" target="_blank">expression tree </a>into CAML? The answer is really quite easy (in theory atleast), you only have to recursively visit the different nodes in the expression tree and translate them into the corrresponding CAML.</p>
<p>Let´s look a the code for the ExpressionToCamlParser.<br />
First of all the parser will have a method called Translate:</p>
<pre class="brush: csharp;">
private XElement query = new XElement(&#34;Where&#34;);

public virtual string Translate(Expression expression)
{
   query.Add(Visit(expression));
   return query.ToString(SaveOptions.DisableFormatting);
}
</pre>
<p><strong>Note:</strong> You will see that I have &#8220;hardcoded&#8221; the startingpoint to &#8220;Where&#8221;. For this example that is fine but feel free to change the implementation to fit your needs. Remember that I will take babysteps here and this is not meant to be a fullblown CAML parser just yet.</p>
<p>I will add the contents of the call to Visit as a childnode to &#8220;Where&#8221;. The visit method looks like this:</p>
<pre class="brush: csharp;">
protected virtual XElement Visit(Expression expression)
{
  if (expression == null)
  {
    return null;
  }

  switch (expression.NodeType)
  {
     case ExpressionType.Call:
       return VisitMethodCall(expression as MethodCallExpression);
     case ExpressionType.MemberAccess:
       return VisitMemberAccess(expression as MemberExpression);
     case ExpressionType.Constant:
       return VisitConstant(expression as ConstantExpression);
     case ExpressionType.And:
     case ExpressionType.AndAlso:
     case ExpressionType.Or:
     case ExpressionType.OrElse:
     case ExpressionType.LessThan:
     case ExpressionType.LessThanOrEqual:
     case ExpressionType.GreaterThan:
     case ExpressionType.GreaterThanOrEqual:
     case ExpressionType.Equal:
     case ExpressionType.NotEqual:
       return VisitBinary(expression as BinaryExpression);
     default:
       return VisitUnknown(expression);
  }
}
</pre>
<p>You will notice that I have taken care of calls of type binary (AND, OR, EQ and so on), constants ( == 1), MemberAccess (will come to that), and MethodCalls( .StartWith() and so on). As I pointed out, this is babysteps so it will not work for all types of expression (not yet atleast).</p>
<p>Let´s first look at binary calls:</p>
<pre class="brush: csharp;">
protected virtual XElement VisitBinary(BinaryExpression binary)
{
  XElement node = ParseNodeType(binary.NodeType);

  XElement left = Visit(binary.Left);
  XElement right = Visit(binary.Right);

  if (left != null &#38;&#38; right != null)
  {
     node.Add(left, right);
  }

  return node;
}
</pre>
<p>So, I first take case of parsing the node type (code below) and then I will visit (this is the recursion) the left part of the tree and the the right part. Then I will add the left and right to the node that I just parsed. This will take care of the AND or OR that have right and left branches (you will see an example of this later on).</p>
<pre class="brush: csharp;">
protected virtual XElement ParseNodeType(ExpressionType type)
{
   XElement node;

   switch (type)
   {
      case ExpressionType.AndAlso:
      case ExpressionType.And:
        node = new XElement(&#34;And&#34;);
        break;
      case ExpressionType.Or:
      case ExpressionType.OrElse:
        node = new XElement(&#34;Or&#34;);
        break;
      case ExpressionType.Equal:
        node = new XElement(&#34;Eq&#34;);
        break;
      case ExpressionType.GreaterThan:
        node = new XElement(&#34;Gt&#34;);
        break;
      case ExpressionType.GreaterThanOrEqual:
        node = new XElement(&#34;Geq&#34;);
        break;
      case ExpressionType.LessThan:
        node = new XElement(&#34;Lt&#34;);
        break;
      case ExpressionType.LessThanOrEqual:
        node = new XElement(&#34;Leq&#34;);
        break;
      default:
        throw new Exception(string.Format(&#34;Unhandled expression type: '{0}'&#34;, type));
   }

       return node;
}
</pre>
<p>Let´s continue with what happens when a call is made to .StartWith (as it is inside my query):</p>
<pre class="brush: csharp;">
protected virtual XElement VisitMethodCall(MethodCallExpression methodcall)
{
  XElement node;
  XElement left = Visit(methodcall.Object);
  XElement right = Visit(methodcall.Arguments[0]);

  switch (methodcall.Method.Name)
  {
     case &#34;Contains&#34;:
       node = new XElement(&#34;Contains&#34;);
       break;
     case &#34;StartsWith&#34;:
       node = new XElement(&#34;BeginsWith&#34;);
       break;
     default:
       throw new Exception(string.Format(&#34;Unhandled method call: '{0}'&#34;, methodcall.Method.Name));
  }

  if (left != null &#38;&#38; right != null)
  {
     node.Add(left, right);
  }

  return node;

}
</pre>
<p>It´s really quite the same as what happens in the binary translation. I visit the left and right subtrees and then I check to see which method is called (and if I can handle that) and lastly a concatination is made.</p>
<p>Ok, now let´s look an how we get the FieldRef and Value out of the expression tree:</p>
<pre class="brush: csharp;">
protected virtual XElement VisitMemberAccess(MemberExpression member)
{

   var expr = member.Expression;
   if (expr.NodeType == ExpressionType.Constant)
   {
      LambdaExpression lambda = Expression.Lambda(member);
      Delegate fn = lambda.Compile();
      return VisitConstant(Expression.Constant(fn.DynamicInvoke(null), member.Type));

   }
   else
   {
      return new XElement(&#34;FieldRef&#34;, new XAttribute(&#34;Name&#34;, member.Member.Name));
   }
}
</pre>
<p>Firstly, note that we will have to compile the lambda expression (in this case that is the SPItem =&#62; SPItem.StartWith(…)) and invoke it to get the actual values.<br />
More on this can be found <a href="http://blogs.msdn.com/mattwar/archive/2007/08/01/linq-building-an-iqueryable-provider-part-iii.aspx">here</a>.</p>
<p>A call to VisitContant is made inside the method and can also be called from the Visit method:</p>
<pre class="brush: csharp;">
protected virtual XElement VisitConstant(ConstantExpression constant)
{
  return new XElement(&#34;Value&#34;, ParseValueType(constant.Type), constant.Value);
}
</pre>
<p>ParseValueType is just a helper method to construct the attribute and looks like this (for now atleast)</p>
<pre class="brush: csharp;">
protected virtual XAttribute ParseValueType(Type type)
{
   string name = &#34;Text&#34;;

   switch (type.Name)
   {
     case &#34;DateTime&#34;:
       name = &#34;DateTime&#34;;
       break;
     case &#34;String&#34;:
       name = &#34;Text&#34;;
       break;
     default:
       throw new Exception(string.Format(&#34;Unhandled value type parser for: '{0}'&#34;, type.Name));
   }

   return new XAttribute(&#34;Type&#34;, name);
}
</pre>
<p>So does it work?</p>
<p>The entire demo code for the Find method looks like this:</p>
<pre class="brush: csharp;">
        public static IList&#60;SharePointItem&#62; FindAll(Expression&#60;Func&#60;SharePointItem, bool&#62;&#62; expression)
        {
            List&#60;SharePointItem&#62; items = new List&#60;SharePointItem&#62;();

            ExpressionToCamlParser parser = new ExpressionToCamlParser();
            string caml = parser.Translate(expression.Body);

            SPSiteDataQuery query = new SPSiteDataQuery
            {
                Query = caml,
                Lists = &#34;&#60;Lists MaxListLimit=\&#34;0\&#34; BaseType=\&#34;1\&#34; /&#62;&#34;,
                Webs = &#34;&#60;Webs Scope=\&#34;SiteCollection\&#34; /&#62;&#34;
            };

            using (SPSite sitecollection = new SPSite(&#34;http://MOSSDEV/sites/books&#34;))
            using (SPWeb site = sitecollection.OpenWeb())
            {
                var result = site.GetSiteData(query);

                foreach (DataRow row in result.AsEnumerable())
                {

                    int itemId = int.Parse(row.Field&#60;string&#62;(&#34;ID&#34;));
                    Guid listId = new Guid(row.Field&#60;string&#62;(&#34;ListID&#34;));
                    Guid siteId = new Guid(row.Field&#60;string&#62;(&#34;WebID&#34;));

                    items.Add(new SharePointItem
                    {
                        ContentTypeId = Book.ContentTypeId,
                        ListId = listId,
                        SiteId = siteId,
                        ListItemId = itemId
                    });
                }
            }

            return items.AsReadOnly();
        }
</pre>
<p>And the output:</p>
<p><img src="http://johanleino.files.wordpress.com/2009/09/092109_1734_usingexpres1.png" alt="" /></p>
<p><strong>Note:</strong> I have made a print of the actual CAML which isn´t in the code though.</p>
<p>So, it does work (with this little simple sample). In the next post I will make it work on some more and tougher CAML and probably refactor my parser a bit, remember I sad babysteps&#8230;</p>
<p>Stay tuned&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Notepad++ 5.5.0]]></title>
<link>http://netvietnam.org/2009/09/21/notepad-5-5-0/</link>
<pubDate>Mon, 21 Sep 2009 13:14:16 +0000</pubDate>
<dc:creator>Nhân Mã</dc:creator>
<guid>http://netvietnam.org/2009/09/21/notepad-5-5-0/</guid>
<description><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></description>
<content:encoded><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></content:encoded>
</item>
<item>
<title><![CDATA[HOWTO : Get the Last ItemID in a list]]></title>
<link>http://koenvosters.wordpress.com/2009/08/20/howto-get-the-last-itemid-in-a-list/</link>
<pubDate>Thu, 20 Aug 2009 09:18:48 +0000</pubDate>
<dc:creator>koenvosters</dc:creator>
<guid>http://koenvosters.wordpress.com/2009/08/20/howto-get-the-last-itemid-in-a-list/</guid>
<description><![CDATA[The following code shows you how to get the last item of an ID in a list. Warning, this code gets yo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The following code shows you how to get the last item of an ID in a list. Warning, this code gets you the last item from that list meaning that if you use this code to get the last item you added, it will go wrong if someone adds an item between you adding it and executing this query. In that case I advise you to get a unique identifier that you add to each item and get the item by that id. </p>
<div style="padding:5px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d84b61d1-696d-4234-aa8d-9399b3ed5ef4" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Code Snippet</div>
<div style="background:#ddd;max-height:300px;overflow:scroll;padding:0;">
<ol style="background:#ffffff;white-space:wrap;margin:0 0 0 35px;">
<li>  <span style="color:#0000ff;">const</span> <span style="color:#0000ff;">string</span> siteurl = <span style="color:#a31515;">&#8220;http://sitecollection&#8221;</span>;</li>
<li style="background:#f3f3f3;">             <span style="color:#0000ff;">using</span> (<span style="color:#0000ff;">var</span> site = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SPSite</span>(siteurl))</li>
<li>             {</li>
<li style="background:#f3f3f3;">                 <span style="color:#0000ff;">using</span> (<span style="color:#0000ff;">var</span> web = site.OpenWeb(<span style="color:#a31515;">&#8220;myweb&#8221;</span>))</li>
<li>                 {</li>
<li style="background:#f3f3f3;">                     <span style="color:#0000ff;">var</span> list = web.Lists[<span style="color:#a31515;">"mylist"</span>];</li>
<li>                     <span style="color:#0000ff;">var</span> query = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SPQuery</span></li>
<li style="background:#f3f3f3;">                                     {</li>
<li>                                         Query = <span style="color:#a31515;">&#8220;   &#60;OrderBy&#62; &#60;FieldRef Name=&#8217;ID&#8217; Ascending=&#8217;False&#8217; /&#62; &#60;/OrderBy&#62;&#8221;</span></li>
<li style="background:#f3f3f3;">                                     };</li>
<li>                     <span style="color:#0000ff;">var</span> items = list.GetItems(query);</li>
<li style="background:#f3f3f3;">                     <span style="color:#2b91af;">SPListItem</span> item;</li>
<li>                     <span style="color:#0000ff;">if</span> (items.Count &#62; 0)</li>
<li style="background:#f3f3f3;">                         item = items[0];</li>
<li>                 }</li>
<li style="background:#f3f3f3;">             \</li>
</ol>
</div>
</div>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Sharepoint Manager 2007 and CAML]]></title>
<link>http://sladescross.wordpress.com/2009/08/04/sharepoint-manager-2007-and-caml/</link>
<pubDate>Tue, 04 Aug 2009 16:42:45 +0000</pubDate>
<dc:creator>sladescross</dc:creator>
<guid>http://sladescross.wordpress.com/2009/08/04/sharepoint-manager-2007-and-caml/</guid>
<description><![CDATA[http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?List=64b38372%2Df170%2D48e3%2D9720%2Dd3398b3f2]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?List=64b38372%2Df170%2D48e3%2D9720%2Dd3398b3f211c&#38;ID=93">http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?List=64b38372%2Df170%2D48e3%2D9720%2Dd3398b3f211c&#38;ID=93</a></p>
<p>Generate CAML by using Sharepoint 2007 and then extract the Sharepoint 2007 CAML using Sharepoint Manager 2007.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SharePoint Terminology and Concepts - Basics of SharePoint ]]></title>
<link>http://dishashah.wordpress.com/2009/07/23/sharepoint-terminology-and-concepts-basics-of-sharepoint/</link>
<pubDate>Thu, 23 Jul 2009 19:03:06 +0000</pubDate>
<dc:creator>dishashah08</dc:creator>
<guid>http://dishashah.wordpress.com/2009/07/23/sharepoint-terminology-and-concepts-basics-of-sharepoint/</guid>
<description><![CDATA[Actually when I have started with SharePoint development, I have many basic questions, like why peop]]></description>
<content:encoded><![CDATA[Actually when I have started with SharePoint development, I have many basic questions, like why peop]]></content:encoded>
</item>
<item>
<title><![CDATA[New U2U CAML Query Builder Feature]]></title>
<link>http://platinumdogs.wordpress.com/2009/07/21/new-u2u-caml-query-builder-feature/</link>
<pubDate>Tue, 21 Jul 2009 15:47:34 +0000</pubDate>
<dc:creator>Phil Harding</dc:creator>
<guid>http://platinumdogs.wordpress.com/2009/07/21/new-u2u-caml-query-builder-feature/</guid>
<description><![CDATA[U2U have launched a new version of the CAML Query Builder tool which you can now install as a featur]]></description>
<content:encoded><![CDATA[U2U have launched a new version of the CAML Query Builder tool which you can now install as a featur]]></content:encoded>
</item>
<item>
<title><![CDATA[Querying Document Libraries (or Pulling Teeth) With CAML]]></title>
<link>http://platinumdogs.wordpress.com/2009/07/21/querying-document-libraries-or-pulling-teeth-with-caml/</link>
<pubDate>Tue, 21 Jul 2009 15:38:06 +0000</pubDate>
<dc:creator>Phil Harding</dc:creator>
<guid>http://platinumdogs.wordpress.com/2009/07/21/querying-document-libraries-or-pulling-teeth-with-caml/</guid>
<description><![CDATA[This post concerns yet another odd &#8220;feature&#8221; exhibited when using CAML to query List or ]]></description>
<content:encoded><![CDATA[This post concerns yet another odd &#8220;feature&#8221; exhibited when using CAML to query List or ]]></content:encoded>
</item>
<item>
<title><![CDATA[Error while updating list items "Cannot complete this action. Please try again."]]></title>
<link>http://sanketinfo.wordpress.com/2009/07/21/error-while-updating-list-items-cannot-complete-this-action-please-try-again/</link>
<pubDate>Tue, 21 Jul 2009 04:10:31 +0000</pubDate>
<dc:creator>Sanket Shah</dc:creator>
<guid>http://sanketinfo.wordpress.com/2009/07/21/error-while-updating-list-items-cannot-complete-this-action-please-try-again/</guid>
<description><![CDATA[I was getting error while updating list items; after looking into each code line by line, I have fou]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I was getting error while <strong>updating list items</strong>; after looking into each code line by line, I have found that error comes due to incorrect syntax near <strong>CAML </strong>query, I feel that SharePoint didn’t give us good user friendly error message to debug into our code. After making correction, my code work well.</p>
<p>Enjoy!!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Becoming a SharePoint Developer]]></title>
<link>http://techjen.wordpress.com/2009/07/17/becoming-a-sharepoint-developer/</link>
<pubDate>Fri, 17 Jul 2009 14:29:40 +0000</pubDate>
<dc:creator>techjen</dc:creator>
<guid>http://techjen.wordpress.com/2009/07/17/becoming-a-sharepoint-developer/</guid>
<description><![CDATA[With our upcoming SharePoint 2007 deployment, I am contemplating whether or not I&#8217;d like to le]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>With our upcoming SharePoint 2007 deployment, I am contemplating whether or not I&#8217;d like to learn <a href="http://www.microsoft.com/click/SharePointDeveloper/">SharePoint development</a>.  I do not have any real development experience aside from some web development (HTML, CSS), and I don&#8217;t think my early years with BASIC or that one Visual Basic course I took in college count.  I wondered whether it was too late in the game to learn programming.</p>
<p>As one should for any major life decisions (or minor), I consulted Google.  I wondered, &#8220;<a href="http://www.google.com/webhp?sourceid=navclient-ff#hl=en&#38;q=is+it+too+late+for+me+to+learn+programming&#38;aq=f&#38;oq=&#38;aqi=&#38;fp=Xmf0jJ9P_V0">Is it too late for me to learn programming</a>?&#8221;  This was an interesting query because Google&#8217;s query suggestions upon typing &#8220;is it too late for me to&#8221; thought I was asking &#8220;<a href="http://www.google.com/webhp?hl=en#hl=en&#38;q=is+it+too+late+for+me+to+go+to+medical+school&#38;aq=0&#38;oq=is+it+too+late+for+me+&#38;aqi=g2&#38;fp=Xmf0jJ9P_V0">Is it too late for me to go to medical school</a>?&#8221; or &#8220;<a href="http://www.google.com/webhp?hl=en#hl=en&#38;q=is+it+too+late+for+me+to+become+a+doctor&#38;aq=1&#38;oq=is+it+too+late+for+me+to&#38;aqi=g2&#38;fp=Xmf0jJ9P_V0">Is it too late for me to become a doctor</a>?&#8221;  I have been watching <a href="http://www.fox.com/house/">House</a> lately, so I did actually consider that as an option momentarily.</p>
<p>The wisdom of Google overwhelmingly answered, NO, it is not too late, and encouraged me to learn programming.  &#8220;<a href="http://www.google.com/webhp?sourceid=navclient-ff#hl=en&#38;q=what+programming+language+should+i+learn+first&#38;aq=f&#38;oq=is+it+too+late+for+me+to+learn+programming&#38;aqi=&#38;aq=f&#38;oq=&#38;aqi=g1&#38;fp=Xmf0jJ9P_V0">What should I start with</a>?&#8221; I implored further.  And the consensus was <a href="http://www.python.org/">Python</a>, favorite of <a href="http://xkcd.com/353/">XKCD</a>.  Certainly a worthy endeavor, but I wondered if I should be more <a href="http://www.google.com/search?hl=en&#38;q=how+to+become+a+sharepoint+developer&#38;sourceid=navclient-ff&#38;rlz=1B3GGGL_enUS335US335&#38;ie=UTF-8">SharePoint specific</a> in my plan?   After all, this calls for .NET development.</p>
<p>In general, the internets tell me that to be a SharePoint developer, you should know these things:</p>
<ul>
<li>Get your <a href="http://www.microsoft.com/learning/en/us/certification/mcsd.aspx">MCSD</a> (Microsoft Certified Solution Developer) &#8211; five exams on .NET (Visual Basic or C#), and XML services.</li>
<li>Learn VB or C# .NET</li>
<li>Also learn <a href="http://www.gregcons.com/KateBlog/SoYouWantToBeASharePointDeveloper.aspx">C++</a></li>
<li>Understand the .NET framework</li>
<li>Understand Web services, ADO.NET, XML/XSLT, and Windows/IIS security</li>
<li>Understand SQL server</li>
<li>Learn ASP .NET development and <em>be a good .NET developer</em></li>
<li>Learn the Sh<span>a</span>rePoint object model</li>
<li>Learn <a href="http://en.wikipedia.org/wiki/Collaborative_Application_Markup_Language">C<span>A</span>ML</a> (Collaborative Application Markup Language)</li>
</ul>
<p>The start of this process, for a non-developer, is learning <a href="http://www.google.com/search?hl=en&#38;rlz=1B3GGGL_enUS335US335&#38;q=should+i+learn+c%23+or+vb.net&#38;aq=f&#38;oq=&#38;aqi=g1">VB.NET or C#.NET</a> (I&#8217;m going to start with C#).  I can probably start at Microsoft&#8217;s <a href="http://msdn.microsoft.com/en-us/beginner/bb308786.aspx">Web Development for Beginners</a> site.</p>
<p>Too bad I can&#8217;t download all this Matrix-style.  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Notepad++ 5.4.5]]></title>
<link>http://netvietnam.org/2009/07/15/notepad-5-4-5/</link>
<pubDate>Wed, 15 Jul 2009 12:23:02 +0000</pubDate>
<dc:creator>Nhân Mã</dc:creator>
<guid>http://netvietnam.org/2009/07/15/notepad-5-4-5/</guid>
<description><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></description>
<content:encoded><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></content:encoded>
</item>
<item>
<title><![CDATA[Notepad++ 5.4.4]]></title>
<link>http://netvietnam.org/2009/07/06/notepad-5-4-4/</link>
<pubDate>Mon, 06 Jul 2009 12:22:56 +0000</pubDate>
<dc:creator>Nhân Mã</dc:creator>
<guid>http://netvietnam.org/2009/07/06/notepad-5-4-4/</guid>
<description><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></description>
<content:encoded><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></content:encoded>
</item>
<item>
<title><![CDATA[The ordering of your CAML query matters...]]></title>
<link>http://blog.henryong.com/2009/06/29/the-ordering-of-your-caml-query-matters/</link>
<pubDate>Tue, 30 Jun 2009 00:52:51 +0000</pubDate>
<dc:creator>Henry</dc:creator>
<guid>http://blog.henryong.com/2009/06/29/the-ordering-of-your-caml-query-matters/</guid>
<description><![CDATA[If you ever catch yourself having to create List or Document Library Views programmatically &#8211; ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>If you ever catch yourself having to create List or Document Library <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spview.aspx" target="_blank">Views</a> programmatically &#8211; beware the CAML monsters!</p>
<p>J/K&#8230;</p>
<p>But you really do want to look out for how you generate and order your CAML if you are creating filtered views. I was working with a colleague a little while back and had the most awesome 2 days worth of troubleshooting sessions you could ever imagine&#8230;Not!</p>
<p>Here are the symptoms and how we troubleshooted:</p>
<p>The custom Web Part creates a unique view to a SharePoint List depending on various input data from a user. When the view is displayed in the regular List view everything looks ok. When that view was switched to the datasheet view, everything looked ok. But when the generated view goes directly into Datasheet View (which was an option), the data in the <strong>Datasheet view was funky</strong>. <strong>It was displaying some List items multiple times and omitting other items. </strong></p>
<p>At first we thought that there might be something wrong with the List integrity, so we exported the List data to Excel. Data was there and it looked fine. Then we looked back at the List and Item ID&#8217;s to see if for some reason there were multiple items with the same data. Nope, the Datasheet view was showing the same items with the same ID&#8217;s multiple times. Then we tried to create a Datasheet view manually to see if it was something with the Web Part code or if it was a SharePoint bug. As it turns out, it was a little bit of both&#8230;</p>
<p>Using <a href="http://codeplex.com/spm" target="_blank">SPManager</a> to carefully inspect and scrutinize all the properties of both the view generated by the custom Web Part and the view that was generated via the web UI we stumbled upon some <strong>suspect CAML</strong>! Dun dun dun&#8230;.</p>
<p><strong>Our custom Web Part was using CAML that looked something like this&#8230;</strong></p>
<pre><strong></strong><strong>&#60;Where&#62;
   &#60;Neq&#62;
      &#60;FieldRef Name="ContentType" /&#62;
      &#60;Value Type="Text"&#62;sdfgdf&#60;/Value&#62;
   &#60;/Neq&#62;
&#60;/Where&#62;
</strong>&#60;OrderBy&#62;
   &#60;FieldRef Name="Title" /&#62;<strong></strong><strong></strong><strong></strong><strong>
&#60;/OrderBy&#62;</strong></pre>
<p><strong>The CAML that was generated via the List interface was like this:</strong></p>
<pre><strong>&#60;OrderBy&#62;
   &#60;FieldRef Name="Title" /&#62;
&#60;/OrderBy&#62;
&#60;Where&#62;
   &#60;Neq&#62;
      &#60;FieldRef Name="ContentType" /&#62;
      &#60;Value Type="Text"&#62;sdfgdf&#60;/Value&#62;
   &#60;/Neq&#62;
&#60;/Where&#62;

</strong></pre>
<p>See the difference? We didn&#8217;t want to believe that that was it at first, but we updated the CAML for the Web Part and that got rid of the duplicate items in Datasheet view bug. What a load of mush right? Oh wells, problem solved.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[CAML and Meeting Workspaces]]></title>
<link>http://spbartnet.wordpress.com/2009/06/10/caml-and-meeting-workspaces/</link>
<pubDate>Wed, 10 Jun 2009 09:28:25 +0000</pubDate>
<dc:creator>Bart Snyckers</dc:creator>
<guid>http://spbartnet.wordpress.com/2009/06/10/caml-and-meeting-workspaces/</guid>
<description><![CDATA[Recently I had to query a list in a meeting workspace, but I got an empty resultset for every meetin]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Recently I had to query a list in a meeting workspace, but I got an empty resultset for every meeting except the first one. Seems that tools like the <a href="http://www.u2u.be/res/Tools/CamlQueryBuilder.aspx" target="_blank">U2U CAML Query Builder</a> and <a href="http://www.codeplex.com/spm" target="_blank">SharePoint Manager 2007</a> were only able to query the items of the first meeting. Time to start googling and after some time I found a <a href="http://sanketinfo.wordpress.com/2009/05/06/challenges-while-working-with-object-model-to-access-recurring-meeting-workspace-site-information/" target="_blank">post of Sanket Shah</a> describing the same problem I had. There is one property, &#8216;query.MeetingInstanceId&#8217;, you have to set on the query, if you want to get items out of a list other than those of the first meeting. It won&#8217;t work if you add the Instance ID column to your CAML query.</p>
<p><span style="text-decoration:underline;">Code example (list is an SPList):</span></p>
<p><span style="color:#0000ff;">Dim</span> query <span style="color:#0000ff;">As </span>SPQuery = <span style="color:#0000ff;">New </span>SPQuery()<br />
query.Query = YourCAMLQuery<br />
query.MeetingInstanceId = instanceID<br />
<span style="color:#0000ff;"> Dim </span>results <span style="color:#0000ff;">As </span>SPListItemCollection = list.GetItems(query)</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Notepad++ 5.4]]></title>
<link>http://netvietnam.org/2009/05/26/notepad-5-4/</link>
<pubDate>Tue, 26 May 2009 09:26:39 +0000</pubDate>
<dc:creator>Nhân Mã</dc:creator>
<guid>http://netvietnam.org/2009/05/26/notepad-5-4/</guid>
<description><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></description>
<content:encoded><![CDATA[Notepad++ là trình biên tập mã nguồn miễn phí (và là công cụ thay thế cho Notepad), hỗ trợ nhiều ngô]]></content:encoded>
</item>
<item>
<title><![CDATA[Sharepoint CAML queries on large lists, performance considerations]]></title>
<link>http://slettemoen.wordpress.com/2009/05/13/sharepoint-caml-queries-on-large-lists-performance-considerations/</link>
<pubDate>Wed, 13 May 2009 14:54:15 +0000</pubDate>
<dc:creator>slettemoen</dc:creator>
<guid>http://slettemoen.wordpress.com/2009/05/13/sharepoint-caml-queries-on-large-lists-performance-considerations/</guid>
<description><![CDATA[I have been struggling with large lists for some time now, and the need to look at performance in qu]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I have been struggling with large lists for some time now, and the need to look at performance in queries where early an issue within a particular project of mine. It all started out with a small list of a couple of thousand items but soon grew to 60k and still growing. The work to fine tune the queries to this list have been going on over a couple of months since everything gradually slowed down. I will try and share some of the things I tried to implement during the developing phase. The queries now run 3 times faster than my previous release and this is due to a number of reasons.</p>
<p><strong>The code</strong></p>
<p>It’s a straight forward query to a list in Sharepoint which contain price information which again is used to validate invoices on external files.</p>
<pre class="code"><span style="color:blue;">        public class </span><span style="color:#2b91af;">PrisDef
        </span>{
            <span style="color:blue;">public string </span>Place { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
            <span style="color:blue;">public string </span>Contract { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
            <span style="color:blue;">public decimal </span>MaxPris { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
            <span style="color:blue;">public decimal </span>MinPris { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
            <span style="color:blue;">public decimal </span>Pris { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
            <span style="color:blue;">public string </span>SKU {<span style="color:blue;">get</span>; <span style="color:blue;">set</span>;}
            <span style="color:blue;">public string </span>InUse { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
        }</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color:blue;">        public static </span><span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">PrisDef</span>&#62; GetPris(<span style="color:blue;">string </span>SKU)
        {
            <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">PrisDef</span>&#62; priser = <span style="color:blue;">new </span><span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">PrisDef</span>&#62;();

            <span style="color:#2b91af;">XmlDocument </span>camlDocument = <span style="color:blue;">new </span><span style="color:#2b91af;">XmlDocument</span>();
            camlDocument.LoadXml(<span style="color:#a31515;">@"&#60;Where&#62;
                                &#60;Eq&#62;
                                    &#60;FieldRef Name='SKU' /&#62;
                                    &#60;Value Type='Integer'&#62;[SKU]&#60;/Value&#62;
                                &#60;/Eq&#62;
                            &#60;/Where&#62;"</span>.Replace(<span style="color:#a31515;">"[SKU]"</span>, SKU));

            <span style="color:blue;">using </span>(<span style="color:#2b91af;">SPSite </span>site = <span style="color:blue;">new </span><span style="color:#2b91af;">SPSite</span>(<span style="color:#a31515;">"https://site"</span>))
            {
                <span style="color:blue;">using </span>(<span style="color:#2b91af;">SPWeb </span>web = site.OpenWeb())
                {

                   <span style="color:#2b91af;">SPQuery </span>query = <span style="color:blue;">new </span><span style="color:#2b91af;">SPQuery</span>();
                   query.Query = camlDocument.InnerXml;
                   query.RowLimit = 1000;
                   <span style="color:#2b91af;">SPListItemCollection </span>items = web.Lists[<span style="color:#a31515;">"Price"</span>].GetItems(query);

                   <span style="color:#2b91af;">IEnumerable</span>&#60;<span style="color:#2b91af;">PrisDef</span>&#62; sortedItems =
                   <span style="color:blue;">from </span>item <span style="color:blue;">in </span>items.OfType&#60;<span style="color:#2b91af;">SPListItem</span>&#62;()
                   <span style="color:blue;">select new </span><span style="color:#2b91af;">PrisDef
                   </span>{
                        Contract = arseString(item[<span style="color:#a31515;">"Contract"</span>]),
                        Place = parseString(item[<span style="color:#a31515;">"Place"</span>]),
                        Pris = parseDecimal(item[<span style="color:#a31515;">"Pris"</span>]),
                        SKU = parseString(item[<span style="color:#a31515;">"SKU"</span>]),
                        MaxPris = parseDecimal(item[<span style="color:#a31515;">"MaxPris"</span>]),
                        MinPris = parseDecimal(item[<span style="color:#a31515;">"MinPris"</span>]),
                        InUse = parseString(item[<span style="color:#a31515;">"Use"</span>])
                    };

                        priser.AddRange(sortedItems);

                        <span style="color:blue;">return </span>priser;
                    }
                }
            }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>                    </p>
<p><strong>A couple of points to notice within the code.</strong></p>
<blockquote><p><span style="text-decoration:underline;">Dispose both spsite and spweb,</span> this is to avoid memory leaks, look at article:</p></blockquote>
<blockquote><p>                <a href="http://msdn.microsoft.com/en-us/library/aa973248.aspx">http://msdn.microsoft.com/en-us/library/aa973248.aspx</a></p></blockquote>
<blockquote><p><span style="text-decoration:underline;">Set rowlimit,</span> this is to avoid lock on a table article</p></blockquote>
<blockquote><p>                 An <strong>SPQuery</strong> object without a value for <strong>RowLimit</strong> will perform poorly and fail on large lists. Specify a <strong>RowLimit</strong> between 1 and 2000 and, if necessary, page through the list.</p></blockquote>
<blockquote><p>                  <a href="http://msdn.microsoft.com/en-us/library/bb687949.aspx">http://msdn.microsoft.com/en-us/library/bb687949.aspx</a></p></blockquote>
<p><strong>the more intresting part is to look at what <em>not</em> todo.:</strong></p>
<blockquote><p><span style="text-decoration:underline;">never use Items</span>, SPList.Items returns all the items in a list and performs badly especially on a large list. I found this especially usefull in tweaking an writing to a list. Notice that I start with a query which return 0 rows, this to avoid items which would have returned the whole list.</p></blockquote>
<pre class="code"><span style="color:blue;">            using </span>(<span style="color:#2b91af;">SPSite </span>site = <span style="color:blue;">new </span><span style="color:#2b91af;">SPSite</span>(<span style="color:#a31515;">"https://site"</span>))
            {
                <span style="color:blue;">using </span>(<span style="color:#2b91af;">SPWeb </span>web = site.OpenWeb())
                {
                    <span style="color:#2b91af;">SPList </span>list = web.Lists[<span style="color:#a31515;">"Log"</span>];
                    <span style="color:#2b91af;">SPQuery </span>query = <span style="color:blue;">new </span><span style="color:#2b91af;">SPQuery </span>{ RowLimit = 0 };
                    <span style="color:#2b91af;">SPListItem </span>listItem = list.GetItems(query).Add();

                    listItem.Web.AllowUnsafeUpdates = <span style="color:blue;">true</span>;
                    listItem[<span style="color:#a31515;">"Errorlog"</span>] = feilMelding;

                    listItem.Update();
                    list.Update();
                    web.Update();
                }
            }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Iwould also like to refer to the list of alternatives for SPList.Items on msdn <a href="http://msdn.microsoft.com/en-us/library/bb687949.aspx">http://msdn.microsoft.com/en-us/library/bb687949.aspx</a></p>
<p><strong>Alternatives to SPList.Items</strong></p>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="49%" valign="bottom"><strong>Poor Performing Methods and Properties</strong><strong> </strong></td>
<td width="50%" valign="bottom"><strong>Better Performing Alternatives</strong><strong> </strong></td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPList.Items.Count</strong></td>
<td width="50%" valign="top"><strong>SPList.ItemCount</strong></td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPList.Items.XmlDataSchema</strong></td>
<td width="50%" valign="top">Create an <strong>SPQuery</strong> object to retrieve only the items you want.</td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPList.Items.NumberOfFields</strong></td>
<td width="50%" valign="top">Create an <strong>SPQuery</strong> object (specifying the <strong>ViewFields</strong>) to retrieve only the items you want.</td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPList.Items[System.Guid] </strong></td>
<td width="50%" valign="top"><strong>SPList.GetItemByUniqueId(System.Guid) </strong></td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPList.Items[System.Int32] </strong></td>
<td width="50%" valign="top"><strong>SPList.GetItemById(System.Int32) </strong></td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPList.Items.GetItemById(System.Int32) </strong></td>
<td width="50%" valign="top"><strong>SPList.GetItemById(System.Int32) </strong></td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPList.Items.ReorderItems(System.Boolean[],System.Int32[],System.Int32) </strong></td>
<td width="50%" valign="top">Perform a paged query by using <strong>SPQuery</strong> and reorder the items within each page.</td>
</tr>
<tr>
<td width="49%" valign="top"><strong>SPFolder.Files.Count</strong></td>
<td width="50%" valign="top"> </td>
</tr>
</tbody>
</table>
<p>This is a start, I will try to cover a couple of other topics within performance on large Lists. This is my first blogpost enjoy.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Displaying Columns in a Crosslist DVWP]]></title>
<link>http://mdasblog.wordpress.com/2009/04/21/displaying-columns-in-a-crosslist-dvwp/</link>
<pubDate>Tue, 21 Apr 2009 15:16:57 +0000</pubDate>
<dc:creator>Marc</dc:creator>
<guid>http://mdasblog.wordpress.com/2009/04/21/displaying-columns-in-a-crosslist-dvwp/</guid>
<description><![CDATA[I&#8217;ve alluded to this in the past, but I had a client situation in the last few days that broug]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;ve <a href="http://mdasblog.wordpress.com/2008/09/21/rollup-data-view-web-parts-revisited/">alluded to this in the past</a>, but I had a client situation in the last few days that brought it top of mind again. One of the quirks of a Crosslist DVWP is that you *<strong>must</strong>* specify all columns you would like to display in the CAML for the Data Source. You can add any column in the XSL you want, but if they aren&#8217;t explicitly specified in the CAML, you will get blank results.</p>
<p>Here&#8217;s an example. Say you want to gather the latest announcements from across the Site Collection for display on the Home Page of your Intranet. You&#8217;re displaying the latest 5 announcements, but you realize that annoucements that are expired are still showing up. So, you add a filter to the row select, as below, and you&#8217;re not seeing what you&#8217;d expect.</p>
<pre class="brush: xml;">
&lt;xsl:variable name=&quot;Rows&quot; select=&quot;/dsQueryResponse/Rows/Row[
    (ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') &gt;=
    ddwrt:FormatDateTime(string(@Expires), 1033, 'yyyyMMdd')) or
    string-length(@Expires) = 0
  ]&quot;/&gt;
</pre>
<p>You&#8217;ll need to add an explicit FieldRef for the Expires column in your CAML, as below.  (I&#8217;ve added carriage returns and white space into the CAML above for readability, but you can&#8217;t have them in your DVWP.)</p>
<pre class="brush: xml;">
&lt;SharePointWebControls:SPDataSource
  runat=&quot;server&quot;
  DataSourceMode=&quot;CrossList&quot;
  SelectCommand=&quot;
    &lt;View&gt;
      &lt;Webs Scope='SiteCollection'&gt;&lt;/Webs&gt;
      &lt;Lists ServerTemplate='104'&gt;&lt;/Lists&gt;
      &lt;ViewFields&gt;
        &lt;FieldRef Name='ID'/&gt;
        &lt;FieldRef Name='Title'/&gt;
        &lt;FieldRef Name='Body'/&gt;
        &lt;FieldRef Name='FileDirRef'/&gt;
        &lt;FieldRef Name='Created'/&gt;
        &lt;FieldRef Name='Author'/&gt;
        &lt;FieldRef Name='Expires'/&gt;
        &lt;FieldRef Name='PermMask'/&gt;
      &lt;/ViewFields&gt;
    &lt;/View&gt;&quot;
  UseInternalName=&quot;true&quot;
  ID=&quot;dataformwebpart5&quot;&gt;
&lt;/SharePointWebControls:SPDataSource&gt;
</pre>
<p>Once you add the FieldRef to the CAML, the Expires column values are available for use in your filter.</p>
<p>Keep in mind that you need to be careful what you add into your &#60;Viewfields&#62; section. If you add a FieldRef for a column which doesn&#8217;t occur in *all* of the items which you want to retrieve, you will, in effect, be adding a filter to the CAML. Only items which have all of the columns specified in the FieldRefs will be returned.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Is Null Filter Condition for List Views]]></title>
<link>http://spyralout.com/2009/04/02/is-null-filter-condition-for-list-views/</link>
<pubDate>Thu, 02 Apr 2009 22:17:00 +0000</pubDate>
<dc:creator>bazztrap</dc:creator>
<guid>http://spyralout.com/2009/04/02/is-null-filter-condition-for-list-views/</guid>
<description><![CDATA[I have always wondered why SharePoint List Views don&#8217;t have filters for&#160; Is Null and Is N]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I have always wondered why SharePoint List Views don&#8217;t  have filters for&#160; Is Null and Is Not Null when CAML Queries support it.</p>
<p>U2U CAML Creator </p>
<p><a href="http://spyralout.files.wordpress.com/2009/04/image4.png"><img title="image" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="213" alt="image" src="http://spyralout.files.wordpress.com/2009/04/image-thumb4.png?w=529&#038;h=213" width="529" border="0" /></a> </p>
<p>List View </p>
<p><a href="http://spyralout.files.wordpress.com/2009/04/image1.png"><img title="image" style="display:inline;border-width:0;" height="240" alt="image" src="http://spyralout.files.wordpress.com/2009/04/image-thumb1.png?w=344&#038;h=240" width="344" border="0" /></a> </p>
<p>Turns out it does. When you select “is equal to” and “is not equal to” and do not enter any text it generates “IS Null” and “Is Not Null” CAML Queries for the View. </p>
<p>&#160;</p>
<p><a href="http://spyralout.files.wordpress.com/2009/04/image2.png"><img title="image" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="119" alt="image" src="http://spyralout.files.wordpress.com/2009/04/image-thumb2.png?w=345&#038;h=119" width="345" border="0" /></a> </p>
<p>Result into this</p>
<p><a href="http://spyralout.files.wordpress.com/2009/04/image3.png"><img title="image" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="99" alt="image" src="http://spyralout.files.wordpress.com/2009/04/image-thumb3.png?w=388&#038;h=99" width="388" border="0" /></a> </p>
<p>&#160;</p>
</p>
<p>Tools used:</p>
<p><a href="http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1315" target="_blank">U2U CAML Builder</a></p>
<p><a href="http://www.codeplex.com/SPCamlViewer" target="_blank">STRAMIT CAML Viewer</a></p>
<p>Rohan</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
