DataBiding Overview

Depending on the configuration of its DataSource, the UI for ASP.NET Core FileManager provides different types of data binding.

Remote Binding

The Telerik UI for ASP.NET Core FileManager provides its own ContentProviderController which you need to inherit, in order to use the inbuilt read, create, update and destroy methods. As those as virtual methods, they can be overwritten and extended.

To bind the FileManager to remote data, specify the dataSource option and supply the object with the needed endpoints for read, create, update and destroy operations. The following example demonstrates such implementation, where the FileManagerData inherits the ContentProviderController:

   @(Html.Kendo().FileManager()
    .Name("filemanager")
    .DataSource(ds =>
        {
            ds.Read(operation => operation
            .Type(HttpVerbs.Post)
            .Action("Read", "FileManagerData")
        );
        ds.Destroy(operation => operation
            .Type(HttpVerbs.Post)
            .Action("Destroy", "FileManagerData")
        );
        ds.Create(operation => operation
            .Type(HttpVerbs.Post)
            .Action("Create", "FileManagerData")
        );
        ds.Update(operation => operation
            .Type(HttpVerbs.Post)
            .Action("Update", "FileManagerData")
        );
    })
    .UploadUrl("Upload", "FileManagerData")   
)
 // GET: /FileManager/
        private const string contentFolderRoot = "~/Content/";
        private const string prettyName = "Folders/";
        private static readonly string[] foldersToCopy = new[] { "~/Content/shared/filemanager" };


        /// <summary>
        /// Gets the base paths from which content will be served.
        /// </summary>
        public override string ContentPath
        {
            get
            {
                return CreateUserFolder();
            }
        }

        /// <summary>
        /// Gets the valid file extensions by which served files will be filtered.
        /// </summary>
        public override string Filter
        {
            get
            {
                return "*.*";
            }
        }

        private string CreateUserFolder()
        {
            var virtualPath = Path.Combine(contentFolderRoot, "UserFiles", prettyName);

            var path = Server.MapPath(virtualPath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                foreach (var sourceFolder in foldersToCopy)
                {
                    CopyFolder(Server.MapPath(sourceFolder), path);
                }
            }
            return virtualPath;
        }

        private void CopyFolder(string source, string destination)
        {
            if (!Directory.Exists(destination))
            {
                Directory.CreateDirectory(destination);
            }

            foreach (var file in Directory.EnumerateFiles(source))
            {
                var dest = Path.Combine(destination, Path.GetFileName(file));
                System.IO.File.Copy(file, dest);
            }

            foreach (var folder in Directory.EnumerateDirectories(source))
            {
                var dest = Path.Combine(destination, Path.GetFileName(folder));
                CopyFolder(folder, dest);
            }
        }

The following list provides information about the default requests and responses for the create, read, destroy operations.

  • Create—Makes a POST request for the creation of a directory with the following parameters.

     {"Name":"...","Size":0,"Path":"...","Extension":".txt","IsDirectory":...,"HasDirectories":...,"Created":"...","CreatedUtc":"...","Modified":"...","ModifiedUtc":"..."}
    
  • Read—Makes a POST request that contains the path parameter to specify the path which is browsed and expects a file listing in the following format:

    [
       {"Name":"Documents","Size":0,"Path":"Documents","Extension":"","IsDirectory":true,"HasDirectories":false,"Created":"\/Date(1578897289317)\/","CreatedUtc":"\/Date(1578897289317)\/","Modified":"\/Date(1578897289332)\/","ModifiedUtc":"\/Date(1578897289332)\/"},
        ...
    ]
    
  • Destroy—Makes a POST request containing FormData with the following parameters:

    • Name—The file or directory to be deleted.
    • Path—The directory in which the file or the directory resides.
    • Extension— The extension of the deleted file. No extension in the data, if a folder is deleted.
    • Size&mdash The file size, as provided by the read response.
    • IsDirectory— Boolean, specifying if the deleted is a file or not.
    • HasDirectories— Boolean, specifying if the deleted contains folders.
    • Created— Created Date of the deleted item.
    • CreatedUtc— Created Date in UTC format of the deleted item.
    • Modified— Modified Date of the deleted item.
    • mModifiedUtc— Created Date in UTC formats of the deleted item.
  • Update—Makes a POST request, containing the FileEntry object. The expected response is a file object in the following format:

     {"Name":"...","Size":0,"Path":"...","Extension":".txt","IsDirectory":...,"HasDirectories":...,"Created":"...","CreatedUtc":"...","Modified":"...","ModifiedUtc":"..."}
    

See Also

​​​​​​​ 

In this article
Not finding the help you need? Improve this article