Query content blocks

You can query a content block by its ID. To search for a content blocks based on other property or criteria, see For developers: Find content blocks.

NOTE: The code examples below work with the ID of the master version of the content block. The examples return the master version. For more information about querying by the ID of the live version and returning the live version, see For developers: Query master and live versions.

To query a content block you can use the Native API or the Fluent API:

Query a content block with the Native API

To query a specific content block using the Native API, you use the ContentManager class. 
The following code queries the content block by its ID:

You use the GetContent method and filter based on the Id property. If the content block does not exist, the method returns null.

To find the content block, you can also use the GetContent method passing contentItemId, in the following way:

ContentItem contentItem = manager.GetContent(contentItemId);

If there is no content block with the specified Id, the call to GetContent(contentItemId) throws an exception of type ItemNotFoundException.

Query a content block with the Fluent API

To query a content block using the Fluent API, you use the content block facade. 
The following code queries the content block by its ID:

You first initialize the plural content block facade using App.WorkWith().ContentItems(). Then, you filter the content blocks based on the Id property. Finally, you use the Get method to get the content block. If the content block does not exist, the method returns null.

To find the content block, you can also use the singular content block facade, in the following way:

ContentItem contentItem = App.WorkWith().ContentItem(contentItemId).Get();

If there is no content block with the specified Id, the call to ContentItem(contentItemId) throws an exception of type ItemNotFoundException.


Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its 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 .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Find content blocks