# Modify list items

Sitefinity CMS allows you to modify a list item through the Lists API.

When modifying a list item, you must perform the following:

1. *Get the master version.*

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

   For more information about querying list items, see [For developers: Query list items](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-list-items)

   For more information about finding specific list items, see [For developers: Find list items](https://www.progress.com/documentation/sitefinity-cms/for-developers-find-list-items).
2. *Get a temp version.*

   Check out the master version to get a temp version of the list item. This is the version you must modify.
3. *Modify the temp version.*

   Use the temp version to modify the list item.
4. *Update the master version.*

   Check in the temp version to transfer the changes to the master version.
5. *Update the live version.*

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

The examples below modify a list item by the *ID* of its master version. For more information about working with the *ID* of the live version, see [For developers: Edit content](https://www.progress.com/documentation/sitefinity-cms/for-developers-edit-content).

## Modifying a list item by its ID

The following examples modify a list item by the *ID* of its master version.

**Native API**

```C#
using System;
using System.Linq;
using Telerik.Sitefinity.Modules.Lists;
using Telerik.Sitefinity.Lists.Model;

namespace SitefinityWebApp
{
    public class ModifyListItems_ModifyListItemNativeAPI
    {
        public void ModifyListItemNativeAPI(Guid masterListItemId, string newContent)
        {
            ListsManager listsManager = ListsManager.GetManager();

            // Get the master version
            ListItem master = listsManager.GetListItems().Where(i => i.Id == masterListItemId).FirstOrDefault();

            if (master != null)
            {
                // Check out the master to get a temp version
                ListItem temp = listsManager.Lifecycle.CheckOut(master) as ListItem;

                // Make the modifications to the temp version
                temp.Content = newContent;

                // Check in the temp and get the updated master version. 
                // After the check in the temp version is deleted.
                master = listsManager.Lifecycle.CheckIn(temp) as ListItem;

                // Publish the master
                listsManager.Lifecycle.Publish(master);

                listsManager.SaveChanges();
            }
        }
    }
}
```

First, you get an instance of the ListsManager class. Then, you get the master version corresponding to the *ID*.

For more information about querying list items, see [For developers: Query list items](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-list-items)

For more information about finding specific list items, see [For developers: Find list items](https://www.progress.com/documentation/sitefinity-cms/for-developers-find-list-items).

Then, you call Lifecycle.CheckOut with the master version as argument to get a temp version of the item. You modify the content of the temp version with *newContent*. Then, you call Lifecycle.CheckIn with the temp version as argument to transfer the changes to the master version. By default, calling the CheckIn method deletes the temp version. Then, you call Lifecycle.Publish with the master version as argument to transfer the changes to the live version. Finally, you call SaveChanges to save all changes.

**Fluent API**

```C#
using System;
using Telerik.Sitefinity;

namespace SitefinityWebApp
{
    public class ModifyListItems_ModifyListItemFluentAPI
    {
        public void ModifyListItemFluentAPI(Guid masterListItemId, string newContent)
        {
            int count = 0;

            // Check whether the item exists
            Telerik.Sitefinity.App.WorkWith().ListItems().Where(i => i.Id == masterListItemId).Count(out count);

            if (count > 0)
            {
                // Use the singular facade to modify the master by the master ID
                App.WorkWith().ListItem(masterListItemId).CheckOut().Do(i =>
                {
                    i.Content = newContent;
                    i.LastModified = DateTime.UtcNow;
                })
                .CheckIn().Publish().SaveChanges();
            }
        }
    }
}
```

First, you check whether an item with the specified *ID* exists. Then, you get the master version with the specified *ID* using the singular facade of the list item.

> info \*\*NOTE:\*\*If there is no item with the specified *Id*, ListItem(masterListItemId) throws an exception of type *ItemNotFoundException*.

For more information about querying list items, see [For developers: Query list items](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-list-items)

For more information about finding specific list items, see [For developers: Find list items](https://www.progress.com/documentation/sitefinity-cms/for-developers-find-list-items).

To get a temp for the item, you use the CheckOut method of the facade. Then, you modify the content with *newContent* in the Do method of the temp facade. You call CheckIn to transfer the changes to the master version of the item. Then, you call Publish to transfer the changes to the live version. Finally, you call SaveChanges to save all changes.
