SaaS CMS has officially launched! Learn more now.

Create a page Programmatically problem


How can I get all the "AvailablePageTypes" from the pagetype? without identifying the correct value, it gives me an error.



Jul 03, 2013 4:02
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));


Jul 03, 2013 9:18

Hi Alf

Thanks for your help, I tried your code, somehow the availablePageTypes.GetSetting(pagetypename) always return empty, I expanded availablePageTypes, I could see all the values from _modelSettingRepository property, but the "GetSetting" seems always return a new instance of AvailableSetting



Jul 03, 2013 16:43

Ok. Strange cause when I do this on AlloyTemplates:


The result is:

Count = 7
    [0]: "ContainerPage"
    [1]: "ProductPage"
    [2]: "StandardPage"
    [3]: "NewsPage"
    [4]: "ArticlePage"
    [5]: "SearchPage"
    [6]: "LandingPage"   

Have you checked that the name of the Page Type you are 100% correct to the Page Type Name. You want the name of the Page Type, not the localized name.

If you have the Type of your Page Type, you can find its name by following:



Another thing you could try if you want to check whether a specific Page Type may be created under another specific Page Type is:

EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.PageTypeAvailability.IAvailablePageTypes>().IsAllowed("StartPage", "StandardPage")


Jul 03, 2013 17:04

ah ha, cuz I used "IncludeOn" attribute not Include, that's why GetSetting return nothing. What's the difference between them? 

Jul 03, 2013 17:12

Take startpage and standardpage for example.

if you write includeon(startpage) on the standardpage it will be added to the available page types on startpage.

If you write include(standardpage) on startpage you will add standardpage on the startpage pretty much the same way as previous example.

it provides different ways to define what page types should be allowed or disallowed as children on other page types.  

Jul 03, 2013 18:16

Hi Alf


Thanks for your clear explaination.  However I don't think the GetSetting works for includeon property but include. I have a landingpage type and detailpage type, I set includeon(landingpage) property on detailpagetype, it's not working. After I change to include, the GetSetting returns the result this time.  

Jul 04, 2013 1:11

Accually I think GetSettings include Page Types added by AvailableOn.

I have made these changes to AlloyTemplates

    GUID = "17583DCD-3C11-49DD-A66D-0DEF0DD601FC",
    GroupName = Global.GroupNames.Products)]
[SiteImageUrl(Global.StaticGraphicsFolderPath + "page-type-thumbnail-product.png")]
    Availability = Availability.Specific,
    IncludeOn = new[] { typeof(StartPage) })]
public class ProductPage : StandardPage

    GroupName = Global.GroupNames.Specialized)]
    Include = new[] { typeof(ContainerPage), typeof(SearchPage), typeof(LandingPage) }, // Pages we can create under the start page...
    ExcludeOn = new[] { typeof(ContainerPage), typeof(ProductPage), typeof(StandardPage), typeof(SearchPage), typeof(LandingPage) })] // ...and underneath those we can't create additional start pages
public class StartPage : SitePageData

Now, the only reference between ProductPage and StartPage is the IncludeOn found on ProductPage. Again, IncludeOn means that the current Page Type (ProductPage) should be included as Allowed Page Type to Start Page. And Include means that ContainerPage SearchPage and LandingPage should be included to the current Page Type (StartPage).

Note that since ProductPage inherits StandardPage I have removed both typeof(ProductPage) and typeof(StandardPage) from the Include on StartPage.

ExcludeOn is not relevant in this example.

This is my result when I run the following code

Count = 4
    [0]: "ContainerPage"
    [1]: "SearchPage"
    [2]: "LandingPage"
    [3]: "ProductPage"

And when I remove IncludedOn the result from the same code does not include ProductPage:

    [0]: "ContainerPage"
    [1]: "SearchPage"
    [2]: "LandingPage"
Jul 04, 2013 23:34
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.