Using getDescendents to get specific contentType


Hi guys,

I am a newibie in episerver. I have been learning and i am kind of stuck in a situation.

I need to read the content of each page or more over each links in epierver. I used getDescendent which gives me whole bunch of ID.

I used

 var contentLoader = ServiceLocator.Current.GetInstance();


I could manupulate the output to get the desired content but it fails when the code finds a folder of type contentfolder as below

EPiServer.Core.TypeMismatchException: Content with id '1012' is of type 'EPiServer.Core.ContentFolder' which does not inherit required type 'EPiServer.Core.PageData'
   at EPiServer.Core.DefaultContentLoader.ThrowTypeMismatchException(ContentReference link, Type actual, Type required)
   at EPiServer.Core.DefaultContentLoader.Get[T](ContentReference contentLink, LoaderOptions loaderOptions)
   at EPiServer.Core.DefaultContentLoader.Get[T](ContentReference contentLink)
   at EPiServerImportService.EPiServerUtil.PopulateContentType()

I could get the desired output using getChildren but i need to loop through descendents and it is bit awakward to explain others.

so, i need to know if i can use geeDescendents to get Id except for ContentFolder.If yes please help me understand it.

Any help will be much appreciated.

Thank you

Apr 28, 2016 9:38


Have a look at the Alloy demo, more specific GetAll<T>(ContentReference rootLink) in the ContentLocator. You could get all descendents of a specific type that way.

Apr 28, 2016 10:53

Thank you Jeroen. much appreciated.

Apr 29, 2016 1:21
* 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.