Tab

FileSystemProviderBase.GetFolders(FileManagerFolder) Method

Override this method to implement getting a collection of folders that are located in the current folder.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

Declaration

public virtual IEnumerable<FileManagerFolder> GetFolders(
    FileManagerFolder parentFolder
)

Parameters

Name Type Description
parentFolder FileManagerFolder

A FileManagerFolder object that is the folder currently being processed.

Returns

Type Description
IEnumerable<FileManagerFolder>

A collection of FileManagerFolder objects.

Remarks

If you create a custom file system provider inherited from the FileSystemProviderBase class, you should override the GetFolders method to get a collection of folders that are located in the current folder.

Examples

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();
        RefreshFolderCache();
    }

    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);
        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());
    }
    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) {
        UpdateAndSubmitChanges(parent,
            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 =>
DataContext.DbFileSystemItems.DeleteOnSubmit(dbItem));
    }
    public override void DeleteFolder(FileManagerFolder folder) {
        UpdateAndSubmitChanges(folder, dbItem =>
DataContext.DbFileSystemItems.DeleteOnSubmit(dbItem));
    }
    public override void MoveFile(FileManagerFile file, FileManagerFolder newParentFolder) {
        UpdateAndSubmitChanges(file, dbItem => dbItem.ParentId =
FindDbFolderItem(newParentFolder).Id);
    }
    public override void MoveFolder(FileManagerFolder folder, FileManagerFolder newParentFolder)
{
        UpdateAndSubmitChanges(folder, dbItem => dbItem.ParentId =
FindDbFolderItem(newParentFolder).Id);
    }
    public override void RenameFile(FileManagerFile file, string name) {
        Upd