Chun Yin
Chun Yin

Reputation: 290

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.

Upvotes: 1

Views: 173

Answers (1)

bdukes
bdukes

Reputation: 155925

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

Upvotes: 2

Related Questions