Delete video libraries

This topic explains how to delete video libraries. The examples below show you how to delete all of the available video libraries or how to delete only a specific video library by its ID.

Deleting a single video library

When deleting a specific video library by its ID, you must perform the following:

  1. Get the video library.

    First, get an instance of the video library that corresponds to the specified ID.

  2. Delete the video library.

    Mark the video library to be deleted and save the changes.

The following code deletes a video library by its ID.

Native API

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

namespace SitefinityWebApp
{
    public class DeleteVideoLibraries_DeleteVideoLibraryNativeAPI
    {
        private void DeleteVideoLibraryNativeAPI(Guid videoLibraryId)
        {
            LibrariesManager manager = LibrariesManager.GetManager();

            VideoLibrary library = manager.GetVideoLibraries().Where(b => b.Id == videoLibraryId).SingleOrDefault();

            if (library != null)
            {
                //Mark the library to be deleted.
                manager.DeleteVideoLibrary(library);

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

First, you get an instance of the LibrariesManager class. Then, you get the video library with the specified ID. To mark the video library to be deleted, you call the DeleteVideoLibrary method of the manager with the instance of the video library as an argument. Finally, you save the changes.

Fluent API

C#
using System;
using Telerik.Sitefinity;

namespace SitefinityWebApp
{
    public class DeleteVideoLibraries_DeleteVideoLibraryFluentAPI
    {
        private void DeleteVideoLibraryFluentAPI(Guid videoLibraryId)
        {
            App.WorkWith().VideoLibrary(videoLibraryId).Delete().SaveChanges();
        }

    }
}

First, you get the singular facade of the video library with the specified ID. To mark the video library to be deleted, you call the Deletemethod of the facade. Finally, you call SaveChanges.

Deleting all video libraries

When deleting all video libraries, you must perform the following:

  1. Get all video libraries.

    Get instances of the available video libraries.

  2. Delete each video library.

    Iterate through the collection and delete each video library.

The following code deletes all video libraries.

Native API

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

namespace SitefinityWebApp
{
    public class DeleteVideoLibraries_DeleteAllVideoLibrariesNativeAPI
    {
        private void DeleteAllVideoLibrariesNativeAPI()
        {
            LibrariesManager manager = LibrariesManager.GetManager();

            var videoLibraries = manager.GetVideoLibraries().ToList();

            foreach (VideoLibrary library in videoLibraries)
            {
                manager.DeleteVideoLibrary(library);
            }

            manager.SaveChanges();
        }
    }
}

First, you get an instance of the LibrariesManager class. Then, you get all of the available video libraries. You iterate through the collection and mark each video library to be deleted. Finally, you save the changes.

Fluent API

C#
using Telerik.Sitefinity;

namespace SitefinityWebApp
{
    public class DeleteVideoLibraries_DeleteAllVideoLibrariesFluentAPI
    {
        private void DeleteAllVideoLibrariesFluentAPI()
        {
            App.WorkWith().VideoLibraries().Delete().SaveChanges();
        }
    }
}

First, you get the plural video libraries facade. To mark each item to be deleted, you call the Delete method of the facade. Finally, you save the changes.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.