Sitecore Query XPath for Finding all Locked Items

Summary

Do you need to find all items in Sitecore that have been locked by any user? Below is an XPath query that will show you just that. Keep in mind that depending on the number of items in your installation, this query could take quite a while. I would not recommend running it in your code in a production environment, but rather using the XPath Builder to find these items and resolving them manually.

/sitecore//*[@__lock!='' and @__lock!='<r />']

How Does it Work?

Let’s break down the components of the query:

/sitecore//*[@__lock!='' and @__lock!='<r />']

Start at the root of the content tree: the sitecore item.

/sitecore//*[@__lock!='' and @__lock!='<r />']

Look at all descendants (recursively check all children).

/sitecore//*[@__lock!='' and @__lock!='<r />']

Only return items whose __lock field is not empty and does not contain <r />, signifying that a lock has been cleared.

Issues or suggestions? Sound off in the comments.