Try our conversational search powered by Generative AI!

Get all the page types including draft pages

Vote:
 

Hi, 

I'm trying to get all the pages of a particular type existing in the episerver tree. The problem is I only get the published pages. Not the ones that are in draft mode. I'm already use two techniques to get the pages:

  var criteria = new PropertyCriteriaCollection
            {
                new PropertyCriteria
                    {
                        Condition = CompareCondition.Equal,
                        Name = "PageTypeID",
                        Type = PropertyDataType.PageType,
                        Value = Instances.GetLocalInstance().Load().ID.ToString(),
                        Required = false
                    }
            };

            var pages = ContentReference.RootPage.FindPagesWithCriteria(criteria).OfType().ToList();

and

this._contentRepository
                        .GetDescendants(articleFolder.ContentLink)
                        .FirstOrDefault(item => string.Equals(item.ImdProductId, page.ImdProductId, StringComparison.CurrentCultureIgnoreCase));

Can you help me please?

#193366
May 29, 2018 14:25
Vote:
 

One way to solve this is to using GetChildren but with the language selector. This method only returns the published pages. When we use the Language selector we have all the pages.

Example:

articlePages = this._contentRepository.GetChildren<ArticlePage>(
                        articleFolder.ContentLink,
                        LanguageSelector.AutoDetect(true)).ToArray();

Thank you

#193384
May 29, 2018 15:04
Vote:
 

If you want to use FindPagesWithCriteria or similar you can use "FindAllPagesWithCriteria" which also requires a language to be defined:

var queryService = ServiceLocator.Current.GetInstance<IPageCriteriaQueryService>();
var pages = queryService.FindAllPagesWithCriteria(PageReference.StartPage, criteria, "en", new LanguageSelector("en"));

Just as a word of caution - FindPagesWithCriteria isn't the most efficient of methods as it calls the database directly, bypassing the cache so I'd consider my options before using it on the public facing part of your site.

#193385
May 29, 2018 15:15
Vote:
 

You could use EPiServer.Core.IContent.IContentModelUsage.ListContentOfContentType(ContentType contentType).

#193415
May 30, 2018 9:06
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.