“does not contain” in CAML

camllistitemsharepoint

In CAML I can query SharePoint Listitems using the "Contains"-element, but there is no "does not contain"-element I could use.

So what is the best way to get the items that do not contain a string? Is there a better way than to loop through each and every item?

Best Answer

The same restriction applies to BeginWith. I do not know any good solution sadly. What you could do: Do a Contains-Query, loop through each item and get the IDs, then do another big query for "ID NotEqual 1 or ID NotEqual 2 or ID NotEqual 3......" Since ID is indexed as far as I know, that should have a smaller impact on the database, but it still smells really bad.

For small list it does not matter, for larger lists i'd use the SQL Server Profiler to see what the impact is.

Related Topic