I'm using this line of code to search for items whose names are exactly the string i provide in the query:

string query = path + "//*[@@templatename = 'Template Folder' and @@name='" + year + "']";

I'm trying now to find a solution to return items whose names at least contain this specific string.

Example : In my content tree i have 2 folders named "2018" I need to retrieve them in case i provide the term "201"

Is that possible ? I can't find any informations in the official documentation. Thank you in advance for your help

  • Can you use something like this: @@name='%" + year + "%' Sep 17, 2018 at 16:36
  • Hey, i tried that in the XPath builder before posting the question and it seems it does not work unfortunately
    – Slrg
    Sep 17, 2018 at 16:40
  • 1
    Just FYI, but this is a recursive sitecore query, which would search your entire content tree (extremely inefficient). You are better suited to use the content search api when search this many items. Sep 18, 2018 at 5:09

1 Answer 1


Sitecore query supports various axes, functions, and operators similar to those used in XPath. You can use The contains() function as follows:

string query = path + "//*[@@templatename = 'Template Folder' and contains(@@name, '" + year + "')]"

List of supported functions:

  1. contains('does this string', 'this string')
  2. startswith('does this string', 'this string')
  3. endswith('does this string', 'this string')
  4. not(condition)
  5. position()
  • Thank you for your answer. I get the following error : "Too many or to few arguments in Contains()"
    – Slrg
    Sep 17, 2018 at 16:49
  • What is the second parameter by the way ? i just noticed there are 2. I don't get the difference
    – Slrg
    Sep 17, 2018 at 16:51
  • Sorry, i updated my answer, i didnt change '=' to be comma Sep 17, 2018 at 16:52
  • Thank you very much. that's exactly what is was looking for!
    – Slrg
    Sep 17, 2018 at 16:53

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.