5

In sitecore i want to get all child and grand child which inherited form "Industrial Product template .

Below are the fast query , but its giving error Error : End of string expected at position 5.

Fast query:

_masterdb.SelectItems("query:/sitecore/content/Product Catalog/Industrial/Products/*[@@templatename='Industrial Product']")

2
  • 2
    Please note that "fast" doesn't nescessarely mean fast. You probably want to look into indexing to solve what you need. Commented Feb 27, 2014 at 8:03
  • Or since you are using Sitecore 7, use ContentSearchManager and LINQ to Sitecore if you don't want to create your own search indexes
    – jammykam
    Commented Feb 27, 2014 at 16:50

4 Answers 4

7

Your query is not a fast query, if you use the following query, it worked for me:

_masterdb.SelectItems("fast:/sitecore/content/Product Catalog/Industrial/Products//*[@@templatename='Industrial Product']");

There are two changes in this query:

  • Replace the keyword query at the beginning to fast. This means that it is not a "normal" Sitecore Query, it becomes a Sitecore Fast Query. Please read this guide for more informations about using fast queries.
  • Before selecting your items with *[@@templatename='Industrial Product'], I've added a double slash //. This means, that it searched recursive for all items with your template. With your query you only search for direct child items.

Also, I would recommend you to using the keyword @@templateid instead of @@templatename, as sitecore climber said it's faster and it's also no problem if you rename the template. So your query could look like this at the end:

fast:/sitecore/content/Product Catalog/Industrial/Products//*[@@templateid='{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}']

Note: This does not only select your children and grand children. This does recursively gives you all items with this template.

2
6

This is not fast query, you are using normal query . Please use something like :

Sitecore.Data.Items.Item[] items = 
 database.SelectItems("fast:/sitecore/content/Product Catalog/Industrial/Products//*[@@templateid='yourTemplateId']"); 

Also please use @@templateid not @@templatename, I made some tests and it's faster using @@templateid.

Also have a look here about using FastQuery.

2

Please use below query

_masterdb.SelectItems("query:/sitecore/content/#Product Catalog#/Industrial/Products//*[@@templatename='Industrial Product']")

0

Try this

_masterdb.SelectItems("fast:/sitecore/content/#Product Catalog#/Industrial/Products//*[@@templatename='Industrial Product']")

or

_masterdb.SelectItems("fast:/sitecore/content/#Product Catalog#/Industrial/Products//*[@@templatename='industrial product']")

In some cases, you may need to escape names that contain spaces, such as @#Updated by#.

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.