Search for page implementing interface?

Vote:
 

Is it possible to search for all pages in EPiServer implementing an interface? Without EPiServer Find?

#75576
Sep 30, 2013 15:34
Vote:
 
private void FindAllPages(List<ContentReference> list, ContentReference parentPage)
{
    var loader = ServiceLocator.Current.GetInstance<IContentLoader>();
    var children = loader.GetChildren<PageData>(parentPage);

    children.ForEach(pg =>
                     {
                         if (pg is ISampleInterface)
                         {
                             list.Add(pg.ContentLink);
                         }

                         FindAllPages(list, pg.ContentLink);
                     });
}

    

and

var list = new List<ContentReference>();
FindAllPages(list, ContentReference.StartPage);

    

#75589
Sep 30, 2013 21:50
Vote:
 

An alternative soultion could be to first iterate over all ContentTypes returned from IContentTypeRepository.List and get those contentTypes where ModelType is assignable to the interface.

Then for each ot the content types found above call IContentModelUsage.ListContentOfContentType

Note that both my suggestion and Valdis suggestion (which also have the consequence that it will load up all pages to the cache) might take a considerable time to execute (especially for large sites). So if it is acceptable for the customer you should consider caching the result and then perhaps have a background timer or scheduled job that periodically updates the cached result.

#75712
Oct 04, 2013 9:26
Vote:
 

Valdis recursive search works, but it does take some time to execute, guess I'll have to cache it :)

 

#75858
Oct 09, 2013 9:51
Vote:
 

Nobody said it will come at no cost :)

#75859
Oct 09, 2013 10:03
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.