Search code examples
c#sharepoint-2010caml

CAML query to retrieve a list of users items with ids in a list


I am a beginner in SharePoint using CAML query to get a list of user items from a SharePoint list.

The data I have is a userid list like below:

1 2 3 4 5

Now I want to write a CAML query to retrieve the user items from a SharePoint list where the userid is in (1,2,3,4,5)


Solution

  • If you want to filter data by user ID you need to set LookupId="TRUE" for Author field:

    <Eq>
      <FieldRef Name="Author" LookupId="TRUE" />
      <Value Type="Integer">1</Value>
    </Eq>
    

    If you want to use multiple values for this field you should check IN Element. So your CAML should look like this:

     <In>
      <FieldRef Name="Author" LookupId="True" />
      <Values>
        <Value Type="Integer">1</Value>
        <Value Type="Integer">2</Value>
        <Value Type="Integer">3</Value>
      </Values>
    </In>