Skip to content

CAML Queries, Part 3

June 24, 2010

Just some more CAML queries for your data-gathering pleasure. Even if you don’t use these specific ones (though you might), they might help you out in building your own. Be sure to check out all my posts on CAML, especially Creating Custom Reports with CAML to get you started.

All files created by or last modified by the current user:
Title it what you want, make a description, and leave CAML List Type empty unless you want to filter by data type. Read the entry I linked above to learn how to do that.

<Where>
   <Or>
      <Eq>
         <FieldRef Name="Editor" LookupId="TRUE"/>
         <Value Type="int">
            <UserID/>
         </Value>
      </Eq>
      <Eq>
         <FieldRef Name="Created" LookupId="TRUE"/>
         <Value Type="int">
            <UserID/>
         </Value>
      </Eq>
   </Or>
</Where>

All pages modified in the last 30 days, sorted by date modified, descending
Set CAML List Type to <Lists ServerTemplate='850' /> to limit the query to just Publishing Site Pages. Note the Ascending="False" syntax for descending sort order.

<OrderBy>
   <FieldRef Name="Modified" Ascending="False" />
</OrderBy>
<Where>
   <Geq>
      <FieldRef Name="Modified" />
      <Value Type="DateTime" IncludeTimeValue='TRUE'>
         <Today OffsetDays="-30" />
      </Value>
   </Geq>
</Where>

Unfortunately, it appears that Sharepoint can’t sort by a Choice field in a list, though (at least not out of the box).

Advertisements
One Comment leave one →
  1. paul permalink
    February 22, 2013 2:44 pm

    Can you tell me how I can show all documents that havent been modified in the last 30 days. Help would be much appreciated.

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

%d bloggers like this: