How to retrieve reusable Library elements by Element Type in Umbraco 18?

,

Hi @sandhuravinder

IElementNavigationQueryService is the one you want, though it doesn’t have ContentAtRoot(). It’s all key based, so you get TryGetRootKeys and TryGetRootKeysOfType(alias, out keys) for the roots, then TryGetChildrenKeys and TryGetDescendantsKeysOfType to walk down from there. You then pass those keys through IPublishedElementCache to get the actual IPublishedElement back.

If you only want everything of one type and don’t care about where it sits, IElementCacheService.GetByContentType does it in one call. Bear in mind that’s a database hit and it hands you unpublished items as drafts, so I’d cache it and filter.

(Researched with the help of AI and fact checked against the Umbraco course code).

Justin