Good morning !

I have a really big question, and I found absolutely no good answer to it. I have a SP2013 on premise. I need to display content only by using Content Query WP (my client does not have the good licence to use CSWP). My question is : how to filter my items by "not beginning with" or "not containing"?

What I have :

A site collection named SC, several children displayed by http://SC/s1, http://SC/s2, http://SC/s3, http://SC/s4 and so on... Every of my subsites do have several children of his own. For our example, my subsite s2 has like 3 children named child01, child02 and child03. URLs are as follow : http://SC/s2/children01 ...

I have a CQWP set as follow :

  • Source : Display elements from every sites of this site collection
  • List Type : Document Libraries
  • Content Type : Document Content Type, items from Document (including CT child)

What I want to do:

I would like to set this WebPart to exclude results from a specific subsite (s2) and from every of its children (s2/children01, s2/children02 etc..)

What I did :

I've downloaded my WP and modified its definition. Following the answer by Bishtkuber, i've added "FileRef" as a AdditionalFilterFields and as a CommonViewFields.

Now, I'm struggling with the filter themselves. There is a "Contains" or "Begins with", but there are no opposite of these filters ! no "Does not contain" nor "Does not begin with" !!

What i tried :

I've searched a lot the Internets, and there is no cool response for me : I found this howto exclude terms using a Calculated Column... but this answer is not applicable to my case : I should add a calculated column on every Document Library on every site and subsite. Because my client is allowed to create subsites, it is a problem.

So, do you know how can I add a filter that says "Does not contain" or "Does not begin with" on my CQWP, without creating calculated column, please ?

Thanks a lot. Have a nice day !

1 Answer 1


You might need to override CAML query in your exported webpart definiton and update the query to include the following CAML element

      <FieldRef    Name = "Field_Name"/>
      <Value    Type = "Field_Type"/>
      <XML />


  • Thanks @HarryB, it might be a solution. I still have questions for you though : 1) how do i override the caml query? (i found several sources on the internet, but neither told me the right place of the <property name="QueryOverride"> tag in the webpart xml. 2) Does it goes into a <![CDATA[ tag ? 3) Do i have to encode special characters (like > in &gt; ?) ? 4) If i override the query, i assume i will have to in fact write my whole query in the query override. Am i correct ? Thanks for your knowledges ;)
    – Gaelle
    Commented May 9, 2017 at 14:52
  • 1.The property should be already present in your exported xml as an empty tag. 2. Have a look at my related answer: sharepoint.stackexchange.com/questions/198650/… 3. Dont need to encode 4. Whole query is required, Correct.
    – HarryB
    Commented May 9, 2017 at 15:36
  • rmanimaran.wordpress.com/2011/03/11/…
    – HarryB
    Commented May 9, 2017 at 15:45
  • Hello @HarryB, i've tried to use your sample on a online environment so i wrote <Query> <Where> <NotIncludes> <FieldRef Name="BaseName" /> <Value Type="Text">LEAFLET2.pdf</Value> </NotIncludes> </Where> </Query> in [SP CAML Query Helper ](spcamlqueryhelper.codeplex.com). How i understood the NotIncludes, this query should return every documents with the BaseName different from Leaflet2.pdf ... but the result shown by the helper is just ONE document called .. leafleft2.pdf ........ did i understood something wrong ? Thanks
    – Gaelle
    Commented May 10, 2017 at 8:00
  • You are right -the NotIncludes tag only seems to work as expected with a multichoice look up field.
    – HarryB
    Commented May 10, 2017 at 12:30

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.