Skip to main content
A newer version of this page is available. .

How to: Implement a LINQ to SQL Based File System Provider

  • 11 minutes to read

This example shows how to create a LINQ to SQL based file system provider for the ASPxFileManager. The provider retrieves data from DataContext connected to a database containing file/folder structure and contents. To improve performance, we do the following:- Cache a folder list in memory to decrease the number of recursive LINQ to SQL queries made to a database (see the FolderCache property and the RefreshFolderCache method).- Use delayed loading for the Data property mapped to a database field that stores file contents (the Delay Loaded property is set to True for this property in the DbFileSystemItem entity class).Seealso:E5024: ASPxFileManager - How to implement a List data bound custom file system provider

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web;

public partial class _Default : System.Web.UI.Page
{
    protected void ASPxFileManager1_ItemDeleting(object source, DevExpress.Web.FileManagerItemDeleteEventArgs e) {
        ValidateSiteMode(e);
    }
    protected void ASPxFileManager1_ItemMoving(object source, DevExpress.Web.FileManagerItemMoveEventArgs e) {
        ValidateSiteMode(e);
    }
    protected void ASPxFileManager1_ItemRenaming(object source, DevExpress.Web.FileManagerItemRenameEventArgs e) {
        ValidateSiteMode(e);
    }
    protected void ASPxFileManager1_FolderCreating(object source, DevExpress.Web.FileManagerFolderCreateEventArgs e) {
        ValidateSiteMode(e);
    }
    protected void ASPxFileManager1_FileUploading(object source, DevExpress.Web.FileManagerFileUploadEventArgs e) {
        ValidateSiteMode(e);

    }
    protected void ASPxFileManager1_ItemCopying(object source, FileManagerItemCopyEventArgs e) {
        ValidateSiteMode(e);
    }
    protected void ValidateSiteMode(FileManagerActionEventArgsBase e) {
        e.Cancel = true;
        e.ErrorText = "Data modifications are not allowed in the example.";
    }
}