Edit content

When editing a content item, you must work with its master version. To modify an item, you must perform the following:

  1. Get the master version.

    Get the master version of the content item. When you modify an item, you must not work on its live version.

  2. Get a temp version.

    To get a temp version of the item, check out the master version. This is the version you must modify.

  3. Update the master version.

    Check in the temp version to transfer the changes to the master version.

  4. Update the live version.

    Publish the master version to transfer the changes to the live version.

This topic explains how to modify a content item by its ID

You can perform these actions by using either Native API or Fluent API. Therefore, the sections below provide code snippets for both APIs.

NOTE: In the following examples, news items will be used as content. The code can also be applied to blog posts, list items, events, images, documents, and videos.

Modify an item by the ID of its master version

The following code modifies an item by the ID of its master version.

Native API

 

First, you get an instance of the manager. Then, you get the master version corresponding to the ID. Then, to get a temp version of the item, you call Lifecycle.CheckOut with the master version as argument. You make all the modifications to the temp version. Then, to transfer the changes to the master version, you call Lifecycle.CheckIn with the temp version as argument. By default, when calling theCheckIn method the temp version gets deleted. Then, you call SaveChanges to persist the changes. Finally, to publish the item, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.

Fluent API

 

First, you get the singular facade of the master version with the specified ID. Then, to get the facade for the temp version, you call theCheckOut method. You make all the modifications in the Do method of the temp facade. Then, to transfer the changes to the master version of the item, you call CheckIn. Then, you save the changes by calling SaveChanges. Finally, to publish the news item, you call theMessageWorkflow method of the WorkflowManager class and pass the required parameters.

Modify an item by the ID of its live version

The following code modifies an item by the ID of its live version.

Native API

 

First, you get an instance of the manager. Then, you get the live version corresponding to the ID. Then, to start editing the item and get the master version, you call Lifecycle.Edit. To get a temp version of the item, you call Lifecycle.CheckOut with the master version as argument. You make all the modifications to the temp version. To transfer the changes to the master version, you call Lifecycle.CheckIn with the temp version as argument. By default, when calling the CheckIn method the temp version gets deleted. Then, to persist the changes, you callSaveChanges. Finally, to publish the item, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.

Fluent API

 

First, you get the live version with the specified ID through the plural facade. Then, you get the ID of the master version of the item using the manager exposed by the singular facade. You get the singular facade of the master version. To get the facade for the temp version, you call the CheckOut method. You make all the modifications in the Do method of the temp facade. To transfer the changes to the master version of the item, you call CheckIn. Then, you save the changes by calling SaveChanges. Finally, to publish the news item, you call theMessageWorkflow method of the WorkflowManager class and pass the required parameters.

Was this article helpful?

Next article

Delete content