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.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.