Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Tahir Naveed
Sep 18, 2015
(4 votes)

Code snippet to get Available Page Types for a specific page type

Couple of days back, I have to write some code to produce an excel sheet listing all the page types and the corresponding page types that are allowed to be created under the page type. 

for each page type in the solution,

    produce a list of page types that are allowed to be created under this page type.

This excel sheet will then be used by QA  guys, as a starting point, to write some test scripts for an EPiServer 6 R2 and composer based solution to EPiServer 8 migration/upgrade project. 

To start with, you need to find all the page types in the solution.

Below is simple function to list all the page types

 private IEnumerable<PageType> GetAllPageTypes()
            var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
            return contentTypeRepository.List().OfType<PageType>();

The following snippet (self explanatory I think) will help you identify all the avaialable page types for a particular page type

 void GetAvailableContentTypes(ContentType contentType)
            var contentTypeAvailablilityService = ServiceLocator.Current.GetInstance<ContentTypeAvailabilityService>();

            // Get Available settings
            AvailableSetting setting = contentTypeAvailablilityService.GetSetting(contentType.Name);
            bool allAvailable = setting.Availability == Availability.All ||
                               setting.Availability == Availability.Undefined &&

            var availableList = new List<PageType>();
            if (!allAvailable)
                foreach (PageType pageType in this.GetAllPageTypes())
                    foreach (string str in setting.AllowedContentTypeNames)
                        if (str.Equals(pageType.Name))
            if (allAvailable)
                // All the page types are allowed
                // Allowed page types are in the availableList

Hope this will be useful :)

Sep 18, 2015


Please login to comment.
Latest blogs
Stop Managing Humans in Your CMS

Too many times, a content management system becomes a people management system. Meaning, an organization uses the CMS to manage all the information...

Deane Barker | Nov 30, 2023

A day in the life of an Optimizely Developer - Optimizely CMS 12: The advantages and considerations when exploring an upgrade

GRAHAM CARR - LEAD .NET DEVELOPER, 28 Nov 2023 In 2022, Optimizely released CMS 12 as part of its ongoing evolution of the platform to help provide...

Graham Carr | Nov 28, 2023

A day in the life of an Optimizely Developer - OptiUKNorth Meetup January 2024

It's time for another UK North Optimizely meet up! After the success of the last one, Ibrar Hussain (26) and Paul Gruffydd (Kin + Carta) will be...

Graham Carr | Nov 28, 2023

Publish content to Optimizely CMS using a custom GPT from OpenAI 🤖

Do you find the traditional editor interface complicated and cluttered? Would you like an editorial AI assistant you can chat with? You can!

Tomas Hensrud Gulla | Nov 28, 2023 | Syndicated blog