Custom File System Provider
- 2 minutes to read
ASPxFileManager allows you to implement your own custom file system provider.
Follow the steps below to create a custom provider.
Create a custom provider class that is inherited from the base FileSystemProviderBase class or from one of its ancestors.
public class LinqFileSystemProvider : FileSystemProviderBase { ... }
Implement the required virtual methods in your class. If you inherit from FileSystemProviderBase, you must implement the following methods:
- 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()); } }
Note that you do not need to override all the methods if your provider is inherited from another predefined provider.
Use the ASPxFileManager.CustomFileSystemProvider or ASPxFileManager.CustomFileSystemProviderTypeName property to assign your provider class to ASPxFileManager.
In markup:
<dx:ASPxFileManager ID="ASPxFileManager1" runat="server" CustomFileSystemProviderTypeName="LinqFileSystemProvider" > ... </dx:ASPxFileManager>
Programmatically (on the Page_Init event):
public partial class FileManager_CustomFilterAPI : System.Web.UI.Page { protected void Page_Init(object sender, EventArgs e) { FileManager.CustomFileSystemProvider = new CustomFileSystemProvider(FileManager.Settings.RootFolder); } }
Set the ASPxFileManager.ProviderType property to Custom to use a custom provider in ASPxFileManager.
Online Blogs
ASP.NET File Manager - Create A Custom File System Provider