Geeks With Blogs

News


Rohit Gupta Engaging talk on Microsoft Technologies ....My Resume

If you generate CAML using LINQ to SharePoint in Visual Studio 2010 then you might see this bug popup:

If you are writing a CAML query to filter records based on Date and Time, and this query is generated using LINQ To SharePoint then you will get the following CAML query generated:

<View>
  <Query>
    <Where>
        <And>
          <Eq>
            <FieldRef Name='Title' />
            <Value Type='Text'>{0}</Value>
          </Eq>
          <Lt>
            <FieldRef Name='QuoteTime' IncludeTimeValue='TRUE' />
            <Value Type='DateTime>{1}</Value>
          </Lt>
        </And>
     </Where>
  </Query>
  <RowLimit Paged='TRUE'>100</RowLimit>
</View>

However the above is incorrect since the IncludeTimeValue Attribute is on the wrong element. The correct CAML query is as follows:

<View>
  <Query>
    <Where>
        <And>
          <Eq>
            <FieldRef Name='Title' />
            <Value Type='Text'>{0}</Value>
          </Eq>
          <Lt>
            <FieldRef Name='QuoteTime' />
            <Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value>
          </Lt>
        </And>
     </Where>
  </Query>
  <RowLimit Paged='TRUE'>100</RowLimit>
</View>

Note that the IncludeTimeValue attribute is on the Value Element and not the FieldRef element. Thus if you need to filter records based on Date & Time then include the “IncludeTimeValue” attribute on the Value Element.

Posted on Monday, November 8, 2010 9:57 AM | Back to top


Comments on this post: Include Time when querying SharePoint List using CAML

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Rohit Gupta | Powered by: GeeksWithBlogs.net