I have less than 5000 items in my library. I want to get 530 items by ids. So I am using following query.
<Where>
<In>
<FieldRef Name="ID" />
<Values>
<Value Type="Number">1</Value>
<Value Type="Number">2</Value>
.
.
.
<Value Type="Number">530</Value>
</Values>
</In>
</Where>
If I use this query on list then while iterating SPListItemCollection following exception is occurred.
System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView)
at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
at Microsoft.SharePoint.SPListItemCollection.GetEnumerator()
If I rerun the query with Values from IN operator less than 500 then SPListItemCollection is not throwing an exception.
Does CAML IN operator has limit of having less than equal 500 items? Or is there any other better approach.