Handy CAML Query Snippets

Getting Checked out Files

<Where>
  <IsNotNull>
    <FieldRef Name='CheckoutUser' />
  </IsNotNull>
</Where>

or

<Where>
  <Eq>
    <FieldRef Name='_Level' />
    <Value Type='Integer'>255</Value>
  </Eq>
</Where>

Getting Published Files

<Where>
  <Eq>
    <FieldRef Name='_Level' />
    <Value Type='Integer'>1</Value>
  </Eq>
</Where>

Getting Checked-in Files

<Where>
  <Eq>
    <FieldRef Name='_Level' />
    <Value Type='Integer'>2</Value>
  </Eq>
</Where>

Getting Files Only (i.e. excluding Folders)

<Where>
  <Eq>
    <FieldRef Name='FSObjType' />
    <Value Type='Integer'>0</Value>
  </Eq>
</Where>

Getting Folders Only (including Document Sets)

<Where>
  <Eq>
    <FieldRef Name='FSObjType' />
    <Value Type='Integer'>1</Value>
  </Eq>
</Where>

Comparing URLs

<Where>
  <Eq>
    <FieldRef Name='WorkflowLink' />
    <Value Type='URL'>/subsite/listname/item-url.docx</Value>
  </Eq>
</Where>

Note that you must use a server relative URL when querying against a URL field.

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