Get PageTypeId from ContentType-model

Alexander Wagner
Member since: 2010
 

I've started upgrading one clients Episerver 6-site to Episerver 7 and I need to get the PageTypeId from certain page types in order for the code to work on many places (like sorting, etc).

On their Episerver 6-site we're using PageTypeBuilder which has a GetPageTypeID-method that return the Id but we're switching to Episerver 7's way of building page types so we can't use that method.


I can clearly see the Page type Ids when I hoover over the Create-link on the create new page-page so there must be a way to extract it by code if I know the page-type (typeof(Models.StartPage)

#65314 Jan 25, 2013 17:18
  •  

    Hi,

    var startPageTypeId = 
        ServiceLocator.Current.GetInstance<ContentTypeRepository>()
        .Load<StartPage>()
        .ID;

        

    #65317 Jan 25, 2013 22:25
  • Alexander Wagner
    Member since: 2010
     

    Thank you!

    #65352 Jan 28, 2013 9:49
  • Alexander Wagner
    Member since: 2010
     
    #65419 Jan 29, 2013 15:43
  • Santosh Achanta
    Member since: 2007
     

    Use the interface rather than the concrete class to achieve this because there is a structure map exception when you deal with the class directly.

    So, it is


    var startPageTypeId = ServiceLocator.Current.GetInstance<IContentTypeRepository>().Load<StartPage>().ID;

    #75776 Edited, Oct 07, 2013 1:59