Remote Binding
The Telerik UI for ASP.NET Core FileManager allows you to enable server-side operations. You can achieve this by using a DataSource mediator, which will act as a bridge between the client-side and established server-side remote service operations.
To successfully bind the FileManager to remote data, you must:
- Create helper methods that guarantee the correct processing of the data.
- Configure the
DataSourceoption and set the endpoints for theRead,Create,Update, andDestroyoperations. - Enable the
Uploadoperation.
To ensure the successful adaptation of the CRUD operations, the FileManagerEntry structure must play a key role when formatting the requests. The FileManagerEntry is an abstraction that encapsulates all of meta-information a file can have.
This ensures that the response for each of the CRUD methods are composed as follows:
[
{ "Name":"...",
"Size": 0,
"Path":"...",
"Extension":".txt",
"IsDirectory" true/false,
"HasDirectories": true/false,
"Created":"...",
"CreatedUtc":"...",
"Modified":"...",
"ModifiedUtc":"..."
}
]
The FileManager is familiar with the FileManagerEntry format and uses it to render the established file hierarchy you want to visualize.
To review the FileManagerEntry structure of the folder and files, review the Create a FileContentBrowser Helper Class.
Common Helper Methods
To ensure that the Files are processed correctly not only within the boundaries of the FileManager but also the existing physical file system layer, consider adding the helper methods described below.
The combination of these methods allows you to abstract an additional logical layer for retrieving files and directories by using a FileContentBrowser Helper class.
-
CreateUserFolder()—Has the main responsibility for re-creating folders by using theSystem.IO.DirectoryInfo.CreateDirectory()method.C#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; } -
CreateNewFolder()— Has the main responsibility of creating a purely new folder by creating a newFileEntry.C#protected virtual FileManagerEntry CreateNewFolder(string target, FileManagerEntry entry) { FileManagerEntry newEntry; var path = NormalizePath(target); string physicalPath = EnsureUniqueName(path, entry); Directory.CreateDirectory(physicalPath); newEntry = directoryBrowser.GetDirectory(physicalPath); return newEntry; } -
CopyFolder()—Has the main responsibility of copying folders and files onto a given destination by using theSystem.IO.File.Copy()method.C#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); } } -
CopyDirectory()