New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Create Download Command For The File Manager


Product Progress Telerik UI for ASP.NET MVC


How can I create a download command in the conext menu of the Kendo UI File Manager for Telerik UI for ASP.NET MVC?

Creating a Download Command

As of Kendo UI R1 2020 SP1 the kendo.ui.filemanager namespace exposes the FileManagerCommand class that could be extended to implement a download command.

Initilaize the Kendo FileManager and define a Download command for the Context Menu

        .ContextMenu(context => context.Items(items =>
            items.Add("download").Command("DownloadCommand").Text("Download").SpriteCssClass("k-icon k-i-download");

Extend the FileManagerCommand class and pass the selected file path to a controller action method.

  var filemanagerNS = kendo.ui.filemanager;

      filemanagerNS.commands.DownloadCommand = filemanagerNS.FileManagerCommand.extend({
          exec: function(){
              var that = this,
                  filemanager = that.filemanager, // get the kendo.ui.FileManager instance
                  options = that.options, // get the options passed through the tool
                  target = // is available only when command is executed from the context menu
                  selectedFiles = filemanager.getSelected(); // get the selected files

                  window.location = '/FileManager/Download?path=' + selectedFiles[0].path;


On the server-side you will need to implement a server-side action to return the file for download. The example below extends the File Manager demo for Telerik UI for ASP.NET MVC

  public FileResult Download(string path)
      var virtualPath = "~/Content/UserFiles/Folders/" + path;
      var filePath = HostingEnvironment.MapPath(virtualPath);
      FileInfo file = new FileInfo(filePath);

      System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
          FileName = file.Name,
          Inline = false
      Response.Headers.Add("Content-Disposition", cd.ToString());
      Response.Headers.Add("X-Content-Type-Options", "nosniff");

      string contentType = MimeMapping.GetMimeMapping(file.Name);
      var readStream = System.IO.File.ReadAllBytes(filePath);
      return File(readStream, contentType);

See Also

In this article