Try our conversational search powered by Generative AI!

Using getDescendents to get specific contentType

Vote:
 

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

contentLoader.Get(someId);

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

#147934
Apr 28, 2016 9:38
Vote:
 

Hi,

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.

#147935
Apr 28, 2016 10:53
Vote:
 

Thank you Jeroen. much appreciated.

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