Item CRUD operations

Create an item

You create items using the CreateItem of the IRestClient interface.

The following example create a news item with title Sample title:

You can set a custom field for built-in types using the SetValue method.
The following code creates a news item with title Sample title and sets the value of its MyCustomFieldName field to My custom field value:

The following code creates a press release item with title Sample title and sets the value of its MyCustomFieldName field to My custom field value:

NOTE: You can optionally provide a provider name, which will create the item in a specified provider.

Retrieve a single item

You retrieve items using the GetItem of the IRestClient interface.

You can retrieve a single item, using one of the following methods:

NOTE: These methods retrieve all of the fields of the item - both plain and related.

The IRestClient interface has a method that allows more granular control over the retrieved item’s fields:

The GetItemArgs argument holds properties that enable more granular control over the fetching of an item like in the following example:

NOTE: the Type property is not required, if the generic argument (in this case <NewsDto>) is decorated with the MapppedSitefinityContentTypeAttribute.

EXAMPLE: The following example retrieves a single news item by passing an id only:
restClient.GetItem(Guid.NewGuid().ToString());

Update an item

You update items using the UpdateItem of the IRestClient interface.

The following code updates the title of the news item with the specified ID to Sample title:

You can set a custom field for built-in types using the SetValue method.
The following code updates the title of the news item with the specified ID to Sample title and the value of its MyCustomFieldName field to My custom field value:

The following code updates the title of the press release with the specified ID to Sample title and the value of its MyCustomFieldName field to My custom field value:

Delete an item

You delete items using the DeleteItem of the IRestClient interface.

The following code deletes the news item with the specified ID:

The following code deletes the press release with the specified ID:

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?