DataBiding Overview
Depending on the configuration of its DataSource, the UI for ASP.NET Core FileManager provides different types of data binding.
The Data Binding is part of Telerik UI for ASP.NET Core, a
professional grade UI library with 100+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.
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 aPOST
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 aPOST
request that contains thepath
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 aPOST
request containingFormData
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 theread
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 aPOST
request, containing theFileEntry
object. The expected response is afile
object in the following format:{"Name":"...","Size":0,"Path":"...","Extension":".txt","IsDirectory":...,"HasDirectories":...,"Created":"...","CreatedUtc":"...","Modified":"...","ModifiedUtc":"..."}
See Also
- Overview of Telerik UI for ASP.NET Core FileManager
- Navigation in Telerik UI for ASP.NET Core FileManager
- Preview Panes in Telerik UI for ASP.NET Core FileManager