November Happy Hour will be moved to Thursday December 5th.

Retreive items

Vote:
 

Hello,


How do I retrevie all the published instances of a certain PageType non culture dependant?
For the moment I use this: ServiceLocator.Current.GetInstance<IContentModelUsage>().ListContentOfContentType(contentType) but it return multiple time the reference to the same item with different versions.

 

Regards,

 

Benjamin V.

#72815
Jul 01, 2013 9:25
Vote:
 

I would suggest that you use PageTypeBuilder with a requirement on PageType:

var repository = ServiceLocator.Current.GetInstance<IContentTypeRepository<PageType>>();
var contentType = repository.Load(typeof(YourPageType));
var pageTypeId = contentType.ID;

var collection = new PropertyCriteriaCollection
    {
        new PropertyCriteria
        {
            Required = true,
            Name = "PageTypeID",
            Condition = CompareCondition.Equal,
            Type = PropertyDataType.PageType,
            Value = pageTypeId.ToString(CultureInfo.InvariantCulture)
        }
    };

var queryService = ServiceLocator.Current.GetInstance<IPageCriteriaQueryService>();
pages = queryService.FindPagesWithCriteria(rootPage.PageLink, collection);

You could also run the result in the pages variable through the FilterForVisitor Filter.

This will search directly in your database so if this will be run many times under a short period of time I would suggest you add this to the cache.

#72817
Edited, Jul 01, 2013 9:47
Vote:
 

Hi

I guess the fastest way is to use the FindAllPagesWithCriteria method if you don't have EPiServer Find or similar.

Hope this helps.

Frederik

#72818
Jul 01, 2013 9:49
Vote:
 

If I remember correctly the difference with FindAllPagesWithCriteria and FindPagesWithCriteria would be that FindAllPages does not filter out pages that the visitor cannot access. right?

But running the result through FilterForVisitor would also solve that.

#72819
Jul 01, 2013 9:51
Vote:
 

Thank you very much for your quick respond it work perfectly! Exactly what I need!

#72821
Jul 01, 2013 10:28
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.