A newer version of this page is available. Switch to the current version.

FileSystemProviderBase Class

Serves as the base class for providers that perform operations with the file system.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v19.2.dll


public abstract class FileSystemProviderBase
Public MustInherit Class FileSystemProviderBase


The FileSystemProviderBase class is the base class that implements the common file system provider functionality.

This class can be used as an ancestor of your custom file system provider. In this case, you should provide the implementation of the class's methods. To learn more, see the Custom File System Provider topic.


using DevExpress.Web.ASPxFileManager;
using System.IO;
public class LinqFileSystemProvider : FileSystemProviderBase {
    const int DbRootItemId = 1;
    DbFileSystemDataContext dataContext;
    Dictionary<int, DbFileSystemItem> folderCache;
    string rootFolderDisplayName;

    public LinqFileSystemProvider(string rootFolder)
        : base(rootFolder) {
        this.dataContext = new DbFileSystemDataContext();

    public DbFileSystemDataContext DataContext { get { return dataContext; } }

    // Used to decrease the number of recursive LINQ to SQL queries made to a database
    public Dictionary<int, DbFileSystemItem> FolderCache { get { return folderCache; } }

    public override string RootFolderDisplayName { get { return rootFolderDisplayName; } }

    public override IEnumerable<FileManagerFile> GetFiles(FileManagerFolder folder) {
        DbFileSystemItem dbFolderItem = FindDbFolderItem(folder);
            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);
            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());
    public override DateTime GetLastWriteTime(FileManagerFile file) {
        var dbFileItem = FindDbFileItem(file);
        return dbFileItem.LastWriteTime.GetValueOrDefault(DateTime.Now);

    // File/folder management operations
    public override void CreateFolder(FileManagerFolder parent, string name) {
            dbItem => DataContext.DbFileSystemItems.InsertOnSubmit(new DbFileSystemItem() {
                IsFolder = true,
                LastWriteTime = DateTime.Now,
                Name = name,
                ParentId = dbItem.Id
    public override void DeleteFile(FileManagerFile file) {
        UpdateAndSubmitChanges(file, dbItem =>
    public override void DeleteFolder(FileManagerFolder folder) {
        UpdateAndSubmitChanges(folder, dbItem =>
    public override void MoveFile(FileManagerFile file, FileManagerFolder newParentFolder) {
        UpdateAndSubmitChanges(file, dbItem => dbItem.ParentId =
    public override void MoveFolder(FileManagerFolder folder, FileManagerFolder newParentFolder)
        UpdateAndSubmitChanges(folder, dbItem => dbItem.ParentId =
    public override void RenameFile(FileManagerFile file, string name) {
        UpdateAndSubmitChanges(file, dbItem => dbItem.Name = name);
    public override void RenameFolder(FileManagerFolder folder, string name) {
        UpdateAndSubmitChanges(folder, dbItem => dbItem.Name = name);
    public override void UploadFile(FileManagerFolder folder, string fileName, Stream content) {
            dbItem => DataContext.DbFileSystemItems.InsertOnSubmit(new DbFileSystemItem() {
                Name = fileName,
                Data = ReadAllBytes(content),
                ParentId = dbItem.Id,
                LastWriteTime = DateTime.Now,
                IsFolder = false

    protected void UpdateAndSubmitChanges(FileManagerFile file, Action<DbFileSystemItem> update)
        UpdateAndSubmitChangesCore(FindDbFileItem(file), update);
    protected void UpdateAndSubmitChanges(FileManagerFolder folder, Action<DbFileSystemItem>
update) {
        UpdateAndSubmitChangesCore(FindDbFolderItem(folder), update);
    protected void UpdateAndSubmitChangesCore(DbFileSystemItem dbitem, Action<DbFileSystemItem>
update) {