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);

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
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-35662136-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + ''; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();