# Create video libraries

When creating a video library, you must perform the following steps:

1. *Check whether the video library already exists.*

   Before you create the video library, you must check whether a video library with the same *ID* already exists.
2. *Create the video library.*

   If the video library does not exist, you create a new video library with the specified *ID*.
3. *Set the required properties.*

   When creating a new video library, it is recommended to set at least the following properties:

   * *Title*
   * *LastModified*
   * *DateCreated*
   * *UrlName*

   You can also set any other properties in this step.
4. *Save the video library.*

   Save all changes that you have made to the video library.

The example below shows you how to create a video library with predefined *ID*.

## Creating a video library with predefined ID

The following code creates a video library with the specified *ID* and *Title*.

**Native API**

```C#
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Libraries;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.Videos.ManagingLibraries
{
   public partial class LibrariesSnippets
   {
       private void CreateVideoLibraryNativeAPI(Guid videoLibraryId, string videoLibraryTitle)
       {
           LibrariesManager librariesManager = LibrariesManager.GetManager();
           VideoLibrary library = librariesManager.GetVideoLibraries().Where(b => b.Id == videoLibraryId).FirstOrDefault();

           if (library == null)
           {
               //Create the library.
               library = librariesManager.CreateVideoLibrary(videoLibraryId);

               //Set the properties of the library.
               library.Title = videoLibraryTitle;
               library.DateCreated = DateTime.UtcNow;
               library.LastModified = DateTime.UtcNow;
               library.UrlName = Regex.Replace(videoLibraryTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

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

               //Save the changes.
               librariesManager.SaveChanges();
           }
       }
   }
}

```

First, you get an instance of the *LibrariesManager* class. You check whether a video library with the same *ID* already exists. To create the video library, you call the CreateAlbum method of the *LibrariesManager* class and pass the specified *ID*. You can create a video library with either predefined or auto-generated *ID* depending on which overload of the method you use. Then, you set the properties of the video library object. It is recommended to set at least the following properties: *Title*, *UrlName*, *LastModified*, *DateCreated*. Finally, to save the video library, you call the SaveChanges method of the manager.

**Fluent API**

```C#
using System;
using System.Text.RegularExpressions;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.Videos.ManagingLibraries
{
   public partial class LibrariesSnippets
   {
       public static void CreateVideoLibraryFluentAPI(Guid videoLibraryId, string videoLibraryTitle)
       {
           //Check whether a library with the same ID already exists.
           var count = 0;
           App.WorkWith().VideoLibraries().Where(b => b.Id == videoLibraryId).Count(out count);

           if (count == 0)
           {
               //Create the library.
               App.WorkWith().VideoLibrary().CreateNew(videoLibraryId)
                   //Set the properties of the library.
               .Do(b =>
               {
                   b.Title = videoLibraryTitle;
                   b.DateCreated = DateTime.UtcNow;
                   b.LastModified = DateTime.UtcNow;
                   b.UrlName = Regex.Replace(videoLibraryTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
               })
                   //Save the changes.
               .SaveChanges();
           }
       }
   }
}

```

First, you check whether a video library with the same *ID* already exists. To create the video library, you call the CreateNew method of the singular video library facade. You can create a video library with either predefined or auto-generated *ID* depending on which overload of the method you use. To set the properties of the video library, you call the Do method of the facade. Finally, you save the changes.
