var startPageTypeId = ServiceLocator.Current.GetInstance<ContentTypeRepository>() .Load<StartPage>() .ID;
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;
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)