1

I am working on a console application to integrate with SharePoint Online site collection. and I want a way to get all items that do not contain the word "fail" and do not contain the word "success", but I am not sure how I can specify does not contain inside CAML. here is my current test code:-

CamlQuery camlQuery2 = new CamlQuery();
                camlQuery2.ViewXml = "<View><Query><Where><And><NOT Contain><FieldRef Name='ResultMessage'/>" +
                    "<Value Type='String'>fail</Value></NOT Contain><NOT Contain><FieldRef Name='ResultMessage'/><Value Type='String'>success</Value></NOT Contain></AND></Where></Query></View>";

2 Answers 2

3

How I can specify does not contain inside CAML?

As a short answer, Unfortunately, you CAN'T.

There isn't <NOT Contain> element or any equivalent for <NOT Contain> in Query schema elements


Workarounds

  • You can get the "<FieldRef Name='ResultMessage'/>" and perform logical comparing like

    if (!string.Contains("fail") && !string.Contains("success")).

2

Use<Neq> </Neq> instead:

<View>  
      <Query> 
         <Where><And><Neq><FieldRef Name='ResultMessage' /><Value Type='Text'>success</Value></Neq><Neq><FieldRef Name='ResultMessage' /><Value Type='Text'>fail</Value></Neq></And></Where> 
      </Query> 
</View>
2
  • 1
    Neq is different than "not contain".. is this correct?
    – John John
    Dec 24, 2019 at 12:09
  • Neq means not equal. The caml query would get all items that do not equal "fail" and "success". The same result as "not contain". Dec 25, 2019 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.