Binding to Custom File System Provider
- 2 minutes to read
FileManager allows you to implement a custom system provider.
To create a custom provider, follow the steps below.
Create your own provider class by inheriting it from the base FileSystemProviderBase class.
public class LinqFileSystemProvider : FileSystemProviderBase { // ... }
Provide implementation for the required virtual methods in your class. If you inherit from FileSystemProviderBase, the implementation of the following methods is essential:
- FileSystemProviderBase.GetFiles,
- FileSystemProviderBase.GetFolders,
- FileSystemProviderBase.ReadFile,
- FileSystemProviderBase.Exists.
public class LinqFileSystemProvider : FileSystemProviderBase { // ... public override IEnumerable<FileManagerFile> GetFiles(FileManagerFolder folder) { DbFileSystemItem dbFolderItem = FindDbFolderItem(folder); return from dbItem in DataContext.DbFileSystemItems where !dbItem.IsFolder && dbItem.ParentId == dbFolderItem.Id select new FileManagerFile(this, folder, dbItem.Name); } public override IEnumerable<FileManagerFolder> GetFolders(FileManagerFolder parentFolder) { DbFileSystemItem dbFolderItem = FindDbFolderItem(parentFolder); return from dbItem in FolderCache.Values where dbItem.IsFolder && dbItem.ParentId == dbFolderItem.Id select new FileManagerFolder(this, parentFolder, dbItem.Name); } public override bool Exists(FileManagerFile file) { return FindDbFileItem(file) != null; } public override bool Exists(FileManagerFolder folder) { return FindDbFolderItem(folder) != null; } public override System.IO.Stream ReadFile(FileManagerFile file) { return new MemoryStream(FindDbFileItem(file).Data.ToArray()); } }
Bind the FileManager to your provider class instance via the FileManagerExtension.BindToFileSystemProvider method. FileManager will use your custom provider to access data.
using System.Web.Mvc; namespace MyProject { public partial class HomeController : Controller { public MyProject.Models.LinqFileSystemProvider dataSource = new MyProject.Models.LinqFileSystemProvider(); public ActionResult Index() { return View(dataSource); } [ValidateInput(false)] public ActionResult DataBindingPartial() { return View("DataBindingPartial", dataSource); } } }
@model LinqFileSystemProvider @using(Html.BeginForm()) { @Html.Partial("DataBindingPartial", Model) }
@Html.DevExpress().FileManager(settings => { settings.Name = "fileManager"; settings.CallbackRouteValues = new { Controller = "Home", Action = "DataBindingPartial" }; settings.Settings.InitialFolder = "Salvador Dali\\1936 - 1945"; // Folder within the data source settings.Settings.ThumbnailFolder = Url.Content("~/Content/FileManager/Thumbnails"); settings.SettingsEditing.AllowCreate = true; settings.SettingsEditing.AllowDelete = true; settings.SettingsEditing.AllowMove = true; settings.SettingsEditing.AllowRename = true; }).BindToFileSystemProvider(Model).GetHtml()
Online Demo
See Also