Search code examples
c#asp.netdotnetnuke

How do I get ContentItems from ContentType using DNN?


I'd like to select all contentItems of Fruits contentType and store them into an array for easy access.

public array GetFruitNutrition(int itemId) 
{
    array fruitsArray = DotNetNuke.Entities.Content.Data.DataService.GetContentItemsByContentType(Fruits);
    return fruitsArray[itemId].Nutrition;
}

Are there any ways to make this possible? I'm fine with alternatives too.


Solution

  • Use DotNetNuke.Entities.Content.ContentController.GetContentItemsByContentType instead of going directly to the data service.

    ContentType contentType = new ContentTypeController().GetContentTypes().SingleOrDefault(ct => ct.ContentType == "MyCompany_Fruit");
    ContentItem[] fruit = new ContentController().GetContentItemsByContentType(contentType.ContentTypeId).ToArray();