3

How can I fetch the item by display name?

The below code is not working:

string url = string.Concat("fast:/sitecore/content/KeenanDirect/#" + string.Format(blogtype) + "#//*[@@Display name='",  displayname + "']");
sitecoreItem = database.Items.GetItem(url);
3
  • Can you try in this way: string url = string.Concat("fast:/sitecore/content/KeenanDirect/#" + string.Format(blogtype) + "#//*[@__Display name='", displayname + "']"); sitecoreItem = database.Items.GetItem(url); . Display name is a standafield and field is "__DisplayName" Nov 3, 2017 at 8:35
  • Can you give describe more. I didn't understood
    – Ravindran
    Nov 3, 2017 at 8:43
  • I don't think it is a good idea to get the item by its display name and i would not recommend it Nov 6, 2017 at 18:01

1 Answer 1

6

First of all I do not recommend using FastQuery, because it can be really slow and many people have had problems with it: https://blog.coates.dk/2014/11/19/sitecore-fast-query-syntax-can-kill-your-sql-server-or-website/

But if you still want to use here is the trick:

The field in Sitecore is not Display Name, it is "Display Name". All the standard fields are prefixed by "" 2 underlines char.

Image of Standard Field Definitions

Your fast query should look like this:

fast:/sitecore/content//*[@#__Display Name#='homedisplayname']

The Display Name for my home item is: homedisplayname

I added #field name# because multi word names should be encoded with "#"

I tried fast query in Developer Center and here are the results.

You need to change a bit of your code to have same pattern like my query from Developer Center.

Results of Fast Query in Developer Center

2
  • What you can suggest to use instead of FastQuery? What is the best practice for it? Nov 4, 2017 at 15:04
  • Content search using solr search provider Nov 4, 2017 at 20:37

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.