# Modify videos

When editing a video, you must work with its master version.\
To modify a video, perform the following:

1. Get the master version.\
   Get the master version of the video. When you modify a video, you must not work on its live version.
2. Get a temp version.\
   Check out the master version to get a temp version of the video.
3. Modify the temp version.\
   Set the properties of the temp version to the new values. You can also upload new video data.
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.

> success **EXAMPLE**: Modifying a video by the ID of its master version.\
> The example below shows you how to modify a video 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) in [For developers: Content lifecycle](https://www.progress.com/documentation/sitefinity-cms/for-developers-content-lifecycle).\
> The following code modifies a video by the `ID` of its master version.

**Native API**

```C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Libraries;
using Telerik.Sitefinity.Workflow;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.Videos.ManagingVideos
{
   public partial class VideoSnippets
   {
       private void ModifyVideoNativeAPI(Guid masterVideoId, string newTitle, Stream videoStream, string videoFileName, string videoExtension)
       {
           LibrariesManager librariesManager = LibrariesManager.GetManager();

           //Get the master version.
           Video master = librariesManager.GetVideos().Where(d => d.Id == masterVideoId).FirstOrDefault();

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

               //Make the modifications to the temp version.
               temp.Title = newTitle;
               temp.LastModified = DateTime.UtcNow;
               temp.Urls.Clear();
               temp.UrlName = Regex.Replace(newTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
               temp.MediaFileUrlName = Regex.Replace(videoFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

               //Recompiles and validates the url of the video.
               librariesManager.RecompileAndValidateUrls(temp);

               librariesManager.Upload(temp, videoStream, videoExtension);

               //Checkin the temp and get the updated master version. 
               //After the check in the temp version is deleted.
               master = librariesManager.Lifecycle.CheckIn(temp) as Video;

               librariesManager.SaveChanges();

               //Publish the videoLibrary post.
               var bag = new Dictionary<string, string>();
               bag.Add("ContentType", typeof(Video).FullName);
               WorkflowManager.MessageWorkflow(masterVideoId, typeof(Video), null, "Publish", false, bag);
           }
       }
   }
}
```

First, you get an instance of the `LibrariesManager` class. Then, you get the master version with the specified `ID`. Then, to get a `temp` version of the video, you call `Lifecycle.CheckOut` with the master version as an argument. You make all the modifications to the temp version. In this example, you update the title of the blog post and respectively its URL and upload new video data. Then, to transfer the changes to the master version, you call `Lifecycle.CheckIn` with the temp version as an argument. By default, when calling the `CheckInmethod` the temp version gets deleted. To persist the changes, you call `SaveChanges`. Finally, to publish the master version, you call the `MessageWorkflow` method of the `WorkflowManager` class and pass the required parameters.

**Fluent API**

```C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Workflow;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.Videos.ManagingVideos
{
   public partial class VideoSnippets
   {
       private void ModifyVideoFluentAPI(Guid masterVideoId, string newTitle, Stream videoStream, string videoFileName, string videoExtension)
       {
           var count = 0;

           App.WorkWith().Videos().Where(i => i.Id == masterVideoId).Count(out count);

           if (count > 0)
           {
               App.WorkWith().Video(masterVideoId).CheckOut().Do(video =>
               {
                   video.Title = newTitle;
                   video.LastModified = DateTime.UtcNow;
                   video.Urls.Clear();
                   video.UrlName = Regex.Replace(newTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                   video.MediaFileUrlName = Regex.Replace(videoFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
               }).UploadContent(videoStream, videoExtension).CheckIn().Publish().SaveChanges();
           }
       }
   }
}
```

First, you check whether a video with the specified `ID` exists. Then, you get the singular video facade of the master version with the specified `ID`. Then, 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. In this example, you update the title of the blog post and respectively its URL. To upload new video data, you call the `UploadContent`. Then, to transfer the changes to the master version of the video, you call `CheckIn`. To save the changes, you call `SaveChanges`. Finally, to publish the video, you call the `MessageWorkflow` method of the `WorkflowManager` class and pass the required parameters.
