Sitecore provides you with the facility to download individual files from the Content Editor. Sometimes, content authors might need to download the whole media library or media files of any selected folders in a ZIP file. In this recipe, you will learn how to use Sitecore APIs to download the whole media library folder along with media metadata.
We will first create a Command
class to download the media library folder:
In the
SitecoreCookbook
project, create a newDownloadMediaLibraryFolder
class in theCommands
folder and inherit it from theCommand
class.Override the
Execute()
method of the class as follows:public override void Execute(CommandContext context) { if (context.Items.Length == 1) { Item currentItem = context.Items[0]; DownloadMediaFolder(currentItem); } return; }
Create the
DownloadMediaFolder()
method. Here, we create a ZIP file in theMediaDownload
directory in thetemp
directory of Sitecore. Here, we have collected...