none
Using caml query to get items RRS feed

  • Question

  • Hi all,

    I have a requiremnt like i want to add users to sp group in multiple sitecolls.All site collections are stored in a list.I need a caml query to get first 10 sitecolls then i need to get next 10 sitecolls and then i need to get 10 sitecolls from list.Then i will add one by one.Please help me how to achieve this.

    Regards,

    Praveen

    Thursday, February 7, 2019 5:56 AM

Answers

  • Hi,

    You could filter item Id with condition 1<=Id<=10 for first 10 sitecolls and then 11<=Id<=20 etc...

           ClientContext clientContext = new ClientContext("http://sp/sites/dev/");
                Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("sitecolls");
                clientContext.Load(spList);
                clientContext.ExecuteQuery();
    
                if (spList != null && spList.ItemCount > 0)
                {
                    Microsoft.SharePoint.Client.CamlQuery camlQuery1 = new CamlQuery();
                    camlQuery1.ViewXml =
                       @"<View>  
                <Query> 
                   <Where><And><Geq><FieldRef Name='ID' /><Value Type='Counter'>1</Value></Geq><Leq><FieldRef Name='ID' /><Value Type='Counter'>10</Value></Leq></And></Where> 
                </Query> 
                 <ViewFields><FieldRef Name='Siteurl' /></ViewFields> 
          </View>";
    
                    ListItemCollection listItems1 = spList.GetItems(camlQuery1);
                    clientContext.Load(listItems1);
                    clientContext.ExecuteQuery();
                }

    For next 10 site colls, change the CAML in above code like this:

    camlQuery1.ViewXml =
                       @"<View>  
                <Query> 
                   <Where><And><Geq><FieldRef Name='ID' /><Value Type='Counter'>11</Value></Geq><Leq><FieldRef Name='ID' /><Value Type='Counter'>20</Value></Leq></And></Where> 
                </Query> 
                 <ViewFields><FieldRef Name='Siteurl' /></ViewFields> 
          </View>";

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Praveenrangu Friday, February 8, 2019 8:35 AM
    Friday, February 8, 2019 5:33 AM