Try our conversational search powered by Generative AI!

Get PageTypeId from ContentType-model

Vote:
 

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
Vote:
 

Hi,

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

    

#65317
Jan 25, 2013 22:25
Vote:
 

Thank you!

#65352
Jan 28, 2013 9:49
Vote:
 
#65419
Jan 29, 2013 15:43
Vote:
 

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
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.