How to get pagetype’s AvailablePageTypes programatically?

How to find page type’s available types

IAvailablePageTypes availablePageTypes = ServiceLocator.Current.GetInstance<IAvailablePageTypes>();
AvailableSetting setting = availablePageTypes.GetSetting(this.Name);
IList<string> allowedPageTypeNames = setting.AllowedPageTypeNames;

If you need more information about your available Page Types you can do:

PageTypeRepository repository = ServiceLocator.Current.GetInstance<PageTypeRepository>();
IEnumerable<PageType> availablePageTypes = allowedPageTypeNames.Select(name => repository.Load(name));
You have to use include property not includeon property on your page type, otherwise you will not be able to get any result from GetSetting method.


EPiServer 7 core changes compare to EPiServer 6

For people who used to work on EPiServer 6, the following class diagram illustrates the major changes between them.


In EPiServer 6, all the custom page types(by default) must inherit from PageData  and when you want to reference a page, you use PageReference Type declare a page reference property. However, EPiServer 7 introduced three new types (ContentData,ContentReference and BlockData) to their framework  to make their API more generic.

EPiServer 7 did a great work and made these changes transparently which means you are still able to use the old API to query the data, thanks for EPiServer team save us a lot of hassle.

EPiServer 6 EPiServer 7
Query page API DataFactory.Instance.GetPage(PageReference)  var _repository = ServiceLocator.Current.GetInstance<IContentRepository>();

// pageLink can be either PageRefence or ContentReference