How To Get A List Of All Page Types Defined in Episerver

Episerver provides us developers with loads of useful and extendable APIs. In today's post, I'm going to quickly go over the IContentTypeRepository and how to write some code that will return all of the page types defined in your website.

           var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
           var pageTypeList = contentTypeRepository.List().OfType<PageType>();
You can then use the IContentModelUsage to get a complete usage listing for a particular page type:
          var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();
          var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

          var contentType = contentTypeRepository.Load<ProductPage>();
          var usages = contentModelUsage.ListContentOfContentType(contentType).OrderBy(x => x.Name);

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top