Search for all content blocks

You can get all content blocks with the Native API or with the Fluent API.

Get all content blocks with the Native API

To get all content blocks, you use the ContentManager class.

You first initialize ContentManager. Then, you get all live content blocks using GetContent() and filter based on the Statusproperty:

C#
using System.Linq;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.GenericContent;

namespace SitefinityWebApp
{
   public class QueryContentBlockWithNativeAPI
   {
       public IQueryable<ContentItem> GetAllContentItemsNative()
       {
           ContentManager manager = ContentManager.GetManager();
           IQueryable<ContentItem> allContentItems = manager.GetContent().Where(cI => cI.Status == ContentLifecycleStatus.Live);
           return allContentItems;
       }
   }
}

Get all content blocks with the Fluent API

To get all content blocks using Fluent API, you use the plural content block façade.

You first initialize the plural content block facade using App.WorkWith().ContentItems(). Then, you filter based on the Statusproperty. Finally, to get the content blocks, you use the Get method:

C#
using System.Linq;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;

namespace SitefinityWebApp
{
   public class QueryContentBlockWithFluentAPI
   {
       public IQueryable<ContentItem> GetAllContentItemsFluent()
       {
           IQueryable<ContentItem> allContentItems = App.WorkWith().ContentItems().Where(cI => cI.Status == ContentLifecycleStatus.Live).Get();
           return allContentItems;
       }
   }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.