syncfusion-aspnetcore-file-manager
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing the Syncfusion File Manager Component
实现Syncfusion File Manager组件
The Syncfusion File Manager is a comprehensive, production-ready component for file browsing, management, and organization in web applications. It provides users with an explorer-like interface to navigate file systems, perform file operations (create, rename, delete, copy, move, upload, download), manage file organization, search and filter content, control access permissions, and handle large datasets efficiently through virtualization.
Syncfusion File Manager 是一款功能完备的生产级组件,用于在Web应用中实现文件浏览、管理与组织能力。它为用户提供类资源管理器的界面,可用于导航文件系统、执行文件操作(创建、重命名、删除、复制、移动、上传、下载)、管理文件组织、搜索和过滤内容、控制访问权限,并且通过虚拟化技术高效处理大型数据集。
When to Use This Skill
什么时候使用本技能
File Browsing & Navigation
文件浏览与导航
- Create a file explorer interface: Display folder hierarchies with large icons or detailed list views
- Enable directory navigation: Support breadcrumb navigation, path configuration, and backward navigation
- Display file information: Show file names, sizes, dates, types, and custom properties
- Implement path tracking: Maintain and display current directory path
- Support file previews: Enable image and file preview capabilities
- 构建文件资源管理器界面:支持以大图标或详细列表视图展示文件夹层级
- 启用目录导航:支持面包屑导航、路径配置、回退导航
- 展示文件信息:显示文件名、大小、日期、类型和自定义属性
- 实现路径追踪:维护并展示当前目录路径
- 支持文件预览:启用图片和文件预览能力
File Operations (CRUD)
文件操作(CRUD)
- Create folders: Programmatically create new directories
- Read & list files: Display directory contents with filtering and sorting
- Upload files: Support single, multiple, and directory uploads with progress tracking
- Download files: Enable single and multi-file downloads (with ZIP support)
- Rename files/folders: Change names with validation and duplicate handling
- Copy files/folders: Duplicate files between locations
- Move files/folders: Cut and paste operations with conflict resolution
- Delete files/folders: Remove items with confirmation dialogs
- Get file details: Retrieve detailed metadata and properties
- 创建文件夹:通过代码编程创建新目录
- 读取与列出文件:支持过滤和排序后展示目录内容
- 上传文件:支持单文件、多文件和目录上传,附带进度追踪
- 下载文件:支持单文件和多文件下载(支持打包为ZIP)
- 重命名文件/文件夹:修改名称时附带校验和重复处理逻辑
- 复制文件/文件夹:在不同位置之间复制文件
- 移动文件/文件夹:剪切粘贴操作附带冲突解决逻辑
- 删除文件/文件夹:删除项目时弹出确认对话框
- 获取文件详情:查询详细的元数据和属性信息
File Organization & Search
文件组织与搜索
- Search files: Find items by name with case sensitivity options
- Filter content: Apply custom filters and display only matching items
- Sort files: Order by name, size, date, or custom comparers
- Multi-selection: Select multiple items with Ctrl+Click, Shift+Click, and Ctrl+A
- Range selection: Drag to select multiple contiguous items
- Select all/clear selection: Programmatic selection control
- 搜索文件:支持按名称搜索,可配置大小写敏感选项
- 过滤内容:应用自定义过滤器,仅展示匹配项
- 文件排序:支持按名称、大小、日期或自定义比较器排序
- 多选功能:支持Ctrl+点击、Shift+点击、Ctrl+A选择多个项目
- 范围选择:拖拽选择多个连续项目
- 全选/清空选择:通过代码编程控制选择状态
Upload & Drag-Drop
上传与拖拽
- File upload: Configure upload settings, allowed extensions, file size constraints
- Batch upload: Upload multiple files sequentially or in parallel
- Chunk upload: Handle large files with pause/resume capability
- Directory upload: Upload entire folder structures
- Drag-and-drop: Accept files from external sources or file manager items
- Upload progress: Track upload status and provide user feedback
- 文件上传:配置上传设置、允许的扩展名、文件大小限制
- 批量上传:支持串行或并行上传多个文件
- 分片上传:支持大文件上传,附带暂停/恢复能力
- 目录上传:上传完整的文件夹结构
- 拖拽功能:支持接收外部来源或文件管理器内部的拖拽项目
- 上传进度:追踪上传状态,为用户提供反馈
Display Customization
展示自定义
- View switching: Toggle between large icons view and details view
- Column customization: Configure columns in details view (name, size, date modified, etc.)
- Template customization: Create custom rendering for items and navigation pane
- Thumbnail display: Show image previews in large icons view
- Navigation pane: Configure sidebar with favorite folders and breadcrumb
- Toolbar customization: Add, remove, or customize toolbar items
- Context menu: Configure context menus for files, folders, and layout
- 视图切换:在大图标视图和详情视图之间切换
- 列自定义:配置详情视图的列(名称、大小、修改日期等)
- 模板自定义:为项目和导航栏创建自定义渲染逻辑
- 缩略图展示:在大图标视图中展示图片预览
- 导航栏:配置侧边栏的收藏夹和面包屑
- 工具栏自定义:添加、移除或自定义工具栏项
- 上下文菜单:为文件、文件夹和布局配置上下文菜单
Advanced Features
高级功能
- Virtualization: Render large file lists efficiently with virtual scrolling
- Flat data structure: Load data from arrays without server communication
- State persistence: Remember user preferences across sessions
- RTL support: Support right-to-left layouts for international applications
- Localization: Support multiple languages and locale-specific formatting
- Security & permissions: Control access to folders and files by role or user
- Custom authentication: Add headers, API keys, or tokens to requests
- 虚拟化:通过虚拟滚动高效渲染大型文件列表
- 扁平数据结构:无需服务端通信,直接从数组加载数据
- 状态持久化:跨会话记住用户偏好设置
- RTL支持:为国际化应用支持从右到左的布局
- 本地化:支持多语言和区域特定格式
- 安全与权限:按角色或用户控制文件夹和文件的访问权限
- 自定义身份认证:为请求添加头信息、API密钥或令牌
Quick Start Example
快速入门示例
Controller Code (FileManagerController.cs)
控制器代码(FileManagerController.cs)
csharp
using Microsoft.AspNetCore.Mvc;
using Syncfusion.EJ2.FileManager;
public class FileManagerController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult FileManager(string action, string path)
{
// Handle file operations based on action parameter
if (action == "read")
{
// Return list of files and folders for the given path
return Ok(new {
cwd = new { name = "Root", hasChild = true, filterPath = "/" },
files = new object[] { },
error = (object)null,
details = (object)null
});
}
return Ok();
}
}csharp
using Microsoft.AspNetCore.Mvc;
using Syncfusion.EJ2.FileManager;
public class FileManagerController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult FileManager(string action, string path)
{
// Handle file operations based on action parameter
if (action == "read")
{
// Return list of files and folders for the given path
return Ok(new {
cwd = new { name = "Root", hasChild = true, filterPath = "/" },
files = new object[] { },
error = (object)null,
details = (object)null
});
}
return Ok();
}
}Razor View (Index.cshtml)
Razor视图(Index.cshtml)
html
<ejs-filemanager id="filemanager"
path="/"
width="100%"
height="400px"
allowDragAndDrop="true"
allowMultiSelection="true"
showThumbnail="true"
enablePersistence="true">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
downloadUrl="/FileManager/Download"
uploadUrl="/FileManager/Upload"
getImageUrl="/FileManager/GetImage">
</e-filemanager-ajaxsettings>
</ejs-filemanager>html
<ejs-filemanager id="filemanager"
path="/"
width="100%"
height="400px"
allowDragAndDrop="true"
allowMultiSelection="true"
showThumbnail="true"
enablePersistence="true">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
downloadUrl="/FileManager/Download"
uploadUrl="/FileManager/Upload"
getImageUrl="/FileManager/GetImage">
</e-filemanager-ajaxsettings>
</ejs-filemanager>Navigation Guide
导航指南
Navigate to the appropriate reference file based on your implementation needs:
根据你的实现需求跳转至对应的参考文件:
Getting Started & Setup
入门与配置
📄 Read: references/getting-started.md
- Component installation and package setup
- Basic initialization and rendering
- AJAX endpoint configuration
- Width and height configuration
- View selection (LargeIcons vs Details)
- Initial path configuration
- Locale and RTL setup
- State persistence configuration
📄 阅读: references/getting-started.md
- 组件安装与包配置
- 基础初始化与渲染
- AJAX端点配置
- 宽高配置
- 视图选择(大图标/详情视图)
- 初始路径配置
- 区域设置与RTL配置
- 状态持久化配置
File Operations (CRUD)
文件操作(CRUD)
📄 Read: references/file-operations.md
- Creating new folders programmatically
- Renaming files and folders
- Copying and pasting operations
- Cutting and moving operations
- Deleting files and folders
- Getting file/folder details
- Request and response formats
- Error handling and error codes
- Best practices and patterns
📄 阅读: references/file-operations.md
- 通过代码编程创建新文件夹
- 重命名文件和文件夹
- 复制粘贴操作
- 剪切移动操作
- 删除文件和文件夹
- 获取文件/文件夹详情
- 请求与响应格式
- 错误处理与错误码
- 最佳实践与模式
File Upload & Drag-Drop
文件上传与拖拽
📄 Read: references/file-upload.md
- Upload settings configuration
- File type filtering (allowedExtensions)
- File size constraints (minFileSize, maxFileSize)
- Auto-upload behavior and manual uploads
- Sequential vs parallel upload
- Chunk upload for large files with pause/resume
- Directory (folder) upload support
- Upload events and handlers
- Upload progress tracking
📄 Read: references/drag-and-drop.md
- Enabling drag-and-drop functionality
- Drop zone configuration
- Internal drag-and-drop (between file manager items)
- External drag-and-drop (from desktop or external sources)
- Drag event handlers (fileDragStart, fileDragging, fileDragStop, fileDropped)
- Preventing default browser behavior
- Multi-file drop support
- Custom drag-and-drop styling
📄 阅读: references/file-upload.md
- 上传设置配置
- 文件类型过滤(allowedExtensions)
- 文件大小限制(minFileSize, maxFileSize)
- 自动上传行为与手动上传
- 串行上传vs并行上传
- 大文件分片上传,支持暂停/恢复
- 目录(文件夹)上传支持
- 上传事件与处理器
- 上传进度追踪
📄 阅读: references/drag-and-drop.md
- 启用拖拽功能
- 放置区域配置
- 内部拖拽(文件管理器项目之间)
- 外部拖拽(从桌面或外部来源拖拽)
- 拖拽事件处理器(fileDragStart, fileDragging, fileDragStop, fileDropped)
- 阻止浏览器默认行为
- 多文件放置支持
- 自定义拖拽样式
Display Views & Customization
展示视图与自定义
📄 Read: references/views-overview.md
- Large icons view (default)
- Details view with configurable columns
- Switching between views dynamically
- Custom large icons template
- Column configuration in details view
- Thumbnail display settings
- File extension display control
📄 Read: references/layouts-customization.md
- Navigation pane settings and visibility
- Breadcrumb navigation and customization
- Toolbar configuration and visibility
- Layout responsive settings
- Template-based customization (navigation pane, large icons)
- Mobile view optimization
- Custom navigation items
- Show/hide hidden items
- Show/hide file extensions
📄 阅读: references/views-overview.md
- 大图标视图(默认)
- 可配置列的详情视图
- 动态切换视图
- 自定义大图标模板
- 详情视图的列配置
- 缩略图展示设置
- 文件扩展名展示控制
📄 阅读: references/layouts-customization.md
- 导航栏设置与可见性
- 面包屑导航与自定义
- 工具栏配置与可见性
- 布局响应式设置
- 基于模板的自定义(导航栏、大图标)
- 移动端视图优化
- 自定义导航项
- 显示/隐藏隐藏项
- 显示/隐藏文件扩展名
Selection, Search, Sort & Filter
选择、搜索、排序与过滤
📄 Read: references/selection-modes.md
- Multiple selection (enabled by default)
- Single selection mode
- Range selection with mouse drag
- Checkbox-based selection
- Keyboard shortcuts (Ctrl+A, Ctrl+Click, Shift+Click)
- Selection events (fileSelect, fileSelection)
- Programmatic selection methods
- Clear selection functionality
📄 Read: references/search-sort-filter.md
- Search functionality and settings
- Case-sensitive search options
- Real-time search as user types
- Sort by name, date modified, size
- Custom sort comparers
- Filter type (contains, startswith, endswith)
- Hidden items visibility
- File extension display
📄 阅读: references/selection-modes.md
- 多选(默认启用)
- 单选模式
- 鼠标拖拽范围选择
- 基于复选框的选择
- 键盘快捷键(Ctrl+A, Ctrl+点击, Shift+点击)
- 选择事件(fileSelect, fileSelection)
- 编程式选择方法
- 清空选择功能
📄 阅读: references/search-sort-filter.md
- 搜索功能与设置
- 大小写敏感搜索选项
- 用户输入时实时搜索
- 按名称、修改日期、大小排序
- 自定义排序比较器
- 过滤类型(包含、开头匹配、结尾匹配)
- 隐藏项可见性
- 文件扩展名展示
Toolbar & Context Menu Customization
工具栏与上下文菜单自定义
📄 Read: references/toolbar-customization.md
- Toolbar item configuration
- Default toolbar items list
- Custom toolbar items and actions
- Enable/disable toolbar items dynamically
- Toolbar visibility settings
- Toolbar layout and styling
- Toolbar click event handling
📄 Read: references/context-menu.md
- Context menu settings for files, folders, and layout
- Default context menu items
- Enable/disable menu items dynamically
- Menu item event handling
- Custom menu items and actions
- Menu visibility configuration
- Menu events (menuOpen, menuClick, menuClose)
📄 阅读: references/toolbar-customization.md
- 工具栏项配置
- 默认工具栏项列表
- 自定义工具栏项与动作
- 动态启用/禁用工具栏项
- 工具栏可见性设置
- 工具栏布局与样式
- 工具栏点击事件处理
📄 阅读: references/context-menu.md
- 文件、文件夹、布局的上下文菜单设置
- 默认上下文菜单项
- 动态启用/禁用菜单项
- 菜单项事件处理
- 自定义菜单项与动作
- 菜单可见性配置
- 菜单事件(menuOpen, menuClick, menuClose)
Events & Methods
事件与方法
📄 Read: references/file-events.md
- File Operation Events: beforeDelete, delete, rename, folderCreate, beforeMove, move
- Selection Events: fileSelect, fileSelection
- Navigation Events: fileOpen, fileLoad
- Upload Events: uploadListCreate, success, failure
- AJAX Events: beforeSend, beforeDownload, beforeImageLoad
- Popup Events: popupOpen, beforePopupOpen, popupClose, beforePopupClose
- Toolbar/Menu Events: toolbarClick, toolbarCreate, menuClick, menuOpen, menuClose
- Search Event: search
- Component Lifecycle: created, destroyed
- Event handler patterns and best practices
📄 Read: references/programmatic-methods.md
- Selection Methods: selectAll(), clearSelection(), getSelectedFiles()
- File Operation Methods: createFolder(), deleteFiles(), renameFile(), downloadFiles()
- Navigation Methods: openFile(), traverseBackward(), refreshFiles(), refreshLayout()
- Upload Methods: uploadFiles()
- Dialog Methods: closeDialog()
- Toolbar/Menu Methods: disableToolbarItems(), enableToolbarItems(), disableMenuItems(), enableMenuItems()
- Filter Methods: filterFiles()
- Advanced Methods: getMenuItemIndex(), getToolbarItemIndex()
- Asynchronous operation handling
📄 阅读: references/file-events.md
- 文件操作事件:beforeDelete, delete, rename, folderCreate, beforeMove, move
- 选择事件:fileSelect, fileSelection
- 导航事件:fileOpen, fileLoad
- 上传事件:uploadListCreate, success, failure
- AJAX事件:beforeSend, beforeDownload, beforeImageLoad
- 弹窗事件:popupOpen, beforePopupOpen, popupClose, beforePopupClose
- 工具栏/菜单事件:toolbarClick, toolbarCreate, menuClick, menuOpen, menuClose
- 搜索事件:search
- 组件生命周期:created, destroyed
- 事件处理器模式与最佳实践
📄 阅读: references/programmatic-methods.md
- 选择方法:selectAll(), clearSelection(), getSelectedFiles()
- 文件操作方法:createFolder(), deleteFiles(), renameFile(), downloadFiles()
- 导航方法:openFile(), traverseBackward(), refreshFiles(), refreshLayout()
- 上传方法:uploadFiles()
- 弹窗方法:closeDialog()
- 工具栏/菜单方法:disableToolbarItems(), enableToolbarItems(), disableMenuItems(), enableMenuItems()
- 过滤方法:filterFiles()
- 高级方法:getMenuItemIndex(), getToolbarItemIndex()
- 异步操作处理
Performance & Advanced Features
性能与高级功能
📄 Read: references/virtualization.md
- Virtual scrolling for large file lists
- Virtualization configuration
- Virtualization limitations and workarounds
- Performance optimization for large datasets
- Memory management best practices
- Selecting files with virtualization
📄 Read: references/flat-data-customization.md
- Flat data structure and configuration
- Loading data without server communication
- Local file arrays and JSON data
- Flat data event handling (create, delete, rename, move)
- UI customization (extensions, hidden items, thumbnails)
- Custom file provider implementation
- Lazy loading patterns
📄 阅读: references/virtualization.md
- 大型文件列表的虚拟滚动
- 虚拟化配置
- 虚拟化限制与解决方案
- 大型数据集的性能优化
- 内存管理最佳实践
- 虚拟化场景下的文件选择
📄 阅读: references/flat-data-customization.md
- 扁平数据结构与配置
- 无需服务端通信加载数据
- 本地文件数组与JSON数据
- 扁平数据事件处理(创建、删除、重命名、移动)
- UI自定义(扩展名、隐藏项、缩略图)
- 自定义文件提供器实现
- 懒加载模式
Security & Access Control
安全与访问控制
📄 Read: references/security-basics.md
- HTML sanitization to prevent XSS attacks
- Input validation and error handling
- SQL injection prevention
- File type validation
- Common security vulnerabilities
- Safe file handling practices
- Permission-based access control
📄 Read: references/authentication-headers.md
- Adding headers to AJAX requests
- Before Send event for custom headers
- Bearer token authentication
- API key authentication
- Basic authentication
- Before Download event handling
- Before Image Load event handling
- OAuth token refresh patterns
- Request header patterns and examples
📄 阅读: references/security-basics.md
- HTML sanitization防范XSS攻击
- 输入校验与错误处理
- SQL注入防范
- 文件类型校验
- 常见安全漏洞
- 安全文件处理实践
- 基于权限的访问控制
📄 阅读: references/authentication-headers.md
- 为AJAX请求添加头信息
- 自定义头的Before Send事件
- Bearer token身份认证
- API密钥身份认证
- 基础身份认证
- Before Download事件处理
- Before Image Load事件处理
- OAuth令牌刷新模式
- 请求头模式与示例
Server Integration
服务端集成
📄 Read: references/server-integration.md
- ASP.NET Core backend implementation
- Node.js backend implementation
- Request/response patterns and formats
- Upload request with chunks
- Error handling strategies
- Resumable upload patterns
- File operation request/response structure
📄 阅读: references/server-integration.md
- ASP.NET Core后端实现
- Node.js后端实现
- 请求/响应模式与格式
- 分片上传请求
- 错误处理策略
- 断点续传模式
- 文件操作请求/响应结构
Complete API Reference
完整API参考
📄 Read: references/api-complete-reference.md
- All Properties: ajaxSettings, path, view, width, height, and 40+ more
- All Methods: selectAll(), clearSelection(), createFolder(), deleteFiles(), renameFile(), downloadFiles(), and 15+ more
- All Events: beforeDelete, delete, fileSelect, beforeSend, beforeDownload, beforeImageLoad, and 20+ more
- Type definitions: FileData, AjaxSettingsModel, UploadSettingsModel, etc.
- Complete working examples: Full-featured implementations with all features
📄 阅读: references/api-complete-reference.md
- 所有属性:ajaxSettings, path, view, width, height等40多个属性
- 所有方法:selectAll(), clearSelection(), createFolder(), deleteFiles(), renameFile(), downloadFiles()等15多个方法
- 所有事件:beforeDelete, delete, fileSelect, beforeSend, beforeDownload, beforeImageLoad等20多个事件
- 类型定义:FileData, AjaxSettingsModel, UploadSettingsModel等
- 完整可运行示例:包含所有功能的全功能实现
Common Patterns
常用模式
Pattern 1: Basic Setup with Toolbar and Context Menu
模式1:带工具栏和上下文菜单的基础配置
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager"
path="/"
width="100%"
height="400px">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
uploadUrl="/FileManager/Upload"
downloadUrl="/FileManager/Download"
getImageUrl="/FileManager/GetImage">
</e-filemanager-ajaxsettings>
<e-filemanager-toolbarsettings items="@new string[] {'NewFolder', 'Upload', 'Cut', 'Copy', 'Paste', 'Delete', 'Download', 'Rename', 'Refresh'}">
</e-filemanager-toolbarsettings>
<e-filemanager-contextmenusettings file="@new string[] {'Open', 'Delete', 'Rename', 'Download', 'Details'}"
folder="@new string[] {'Open', 'Delete', 'Rename', 'Download', 'Details'}"
layout="@new string[] {'SortBy', 'View', 'Refresh', 'NewFolder', 'Upload'}">
</e-filemanager-contextmenusettings>
</ejs-filemanager>视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager"
path="/"
width="100%"
height="400px">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
uploadUrl="/FileManager/Upload"
downloadUrl="/FileManager/Download"
getImageUrl="/FileManager/GetImage">
</e-filemanager-ajaxsettings>
<e-filemanager-toolbarsettings items="@new string[] {'NewFolder', 'Upload', 'Cut', 'Copy', 'Paste', 'Delete', 'Download', 'Rename', 'Refresh'}">
</e-filemanager-toolbarsettings>
<e-filemanager-contextmenusettings file="@new string[] {'Open', 'Delete', 'Rename', 'Download', 'Details'}"
folder="@new string[] {'Open', 'Delete', 'Rename', 'Download', 'Details'}"
layout="@new string[] {'SortBy', 'View', 'Refresh', 'NewFolder', 'Upload'}">
</e-filemanager-contextmenusettings>
</ejs-filemanager>Pattern 2: Upload with Validation and Constraints
模式2:带校验和限制的上传功能
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager" path="/">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
uploadUrl="/FileManager/Upload">
</e-filemanager-ajaxsettings>
<e-filemanager-uploadsettings autoUpload="true"
allowedExtensions=".jpg,.png,.pdf,.doc,.docx"
minFileSize="1024"
maxFileSize="5242880">
</e-filemanager-uploadsettings>
</ejs-filemanager>视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager" path="/">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
uploadUrl="/FileManager/Upload">
</e-filemanager-ajaxsettings>
<e-filemanager-uploadsettings autoUpload="true"
allowedExtensions=".jpg,.png,.pdf,.doc,.docx"
minFileSize="1024"
maxFileSize="5242880">
</e-filemanager-uploadsettings>
</ejs-filemanager>Pattern 3: Details View with Custom Columns
模式3:带自定义列的详情视图
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager" view="Details">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
<e-filemanager-detailsviewsettings>
<e-filemanager-detailsviewsettings-columns>
<e-detailsviewcolumn field="name" headerText="Name" minWidth="150" width="200"></e-detailsviewcolumn>
<e-detailsviewcolumn field="_fm_modified" headerText="Date Modified" type="dateTime" minWidth="120" width="150"></e-detailsviewcolumn>
<e-detailsviewcolumn field="size" headerText="Size" minWidth="90" width="120"></e-detailsviewcolumn>
</e-filemanager-detailsviewsettings-columns>
</e-filemanager-detailsviewsettings>
</ejs-filemanager>视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager" view="Details">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
<e-filemanager-detailsviewsettings>
<e-filemanager-detailsviewsettings-columns>
<e-detailsviewcolumn field="name" headerText="Name" minWidth="150" width="200"></e-detailsviewcolumn>
<e-detailsviewcolumn field="_fm_modified" headerText="Date Modified" type="dateTime" minWidth="120" width="150"></e-detailsviewcolumn>
<e-detailsviewcolumn field="size" headerText="Size" minWidth="90" width="120"></e-detailsviewcolumn>
</e-filemanager-detailsviewsettings-columns>
</e-filemanager-detailsviewsettings>
</ejs-filemanager>Pattern 4: Programmatic File Operations
模式4:编程式文件操作
View Code (Index.cshtml):
html
<button onclick="selectAllAndDelete()">Select All & Delete</button>
<ejs-filemanager id="filemanager">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>
<script>
function selectAllAndDelete() {
var filemanager = document.getElementById('filemanager').ej2_instances[0];
filemanager.selectAll();
var selected = filemanager.getSelectedFiles();
var names = selected.map(function(f) { return f.name; });
filemanager.deleteFiles(names);
}
</script>视图代码(Index.cshtml):
html
<button onclick="selectAllAndDelete()">Select All & Delete</button>
<ejs-filemanager id="filemanager">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>
<script>
function selectAllAndDelete() {
var filemanager = document.getElementById('filemanager').ej2_instances[0];
filemanager.selectAll();
var selected = filemanager.getSelectedFiles();
var names = selected.map(function(f) { return f.name; });
filemanager.deleteFiles(names);
}
</script>Pattern 5: Search with Real-Time Filtering
模式5:实时过滤搜索
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager" search="onSearch">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
<e-filemanager-searchsettings allowSearchOnTyping="true"
filterType="contains"
ignoreCase="true">
</e-filemanager-searchsettings>
</ejs-filemanager>
<script>
function onSearch(args) {
console.log('Search query:', args.searchString);
}
</script>视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager" search="onSearch">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
<e-filemanager-searchsettings allowSearchOnTyping="true"
filterType="contains"
ignoreCase="true">
</e-filemanager-searchsettings>
</ejs-filemanager>
<script>
function onSearch(args) {
console.log('Search query:', args.searchString);
}
</script>Pattern 6: Drag-Drop with Upload
模式6:拖拽上传
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager"
allowDragAndDrop="true"
fileDragStart="onFileDragStart"
fileDragStop="onFileDragStop"
fileDropped="onFileDropped">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
uploadUrl="/FileManager/Upload">
</e-filemanager-ajaxsettings>
<e-filemanager-uploadsettings autoUpload="true"
allowedExtensions=".jpg,.png,.pdf">
</e-filemanager-uploadsettings>
</ejs-filemanager>
<script>
function onFileDragStart(args) {
console.log('Drag started:', args.fileDetails);
}
function onFileDragStop(args) {
console.log('Drag stopped');
}
function onFileDropped(args) {
console.log('File dropped:', args.fileDetails);
}
</script>undefined视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager"
allowDragAndDrop="true"
fileDragStart="onFileDragStart"
fileDragStop="onFileDragStop"
fileDropped="onFileDropped">
<e-filemanager-ajaxsettings url="/FileManager/FileManager"
uploadUrl="/FileManager/Upload">
</e-filemanager-ajaxsettings>
<e-filemanager-uploadsettings autoUpload="true"
allowedExtensions=".jpg,.png,.pdf">
</e-filemanager-uploadsettings>
</ejs-filemanager>
<script>
function onFileDragStart(args) {
console.log('Drag started:', args.fileDetails);
}
function onFileDragStop(args) {
console.log('Drag stopped');
}
function onFileDropped(args) {
console.log('File dropped:', args.fileDetails);
}
</script>undefinedPattern 7: Event-Driven File Operations
模式7:事件驱动的文件操作
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager"
beforeDelete="beforeDelete"
delete="onDelete"
beforeSend="beforeSend">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>
<script>
function beforeDelete(args) {
console.log('Before delete:', args.fileDetails);
// Validate or prevent deletion
var isReadOnly = args.fileDetails.some(function(f) { return f.isReadOnly; });
if (isReadOnly) {
args.cancel = true;
}
}
function onDelete(args) {
console.log('File deleted:', args.fileDetails);
// Update UI or log action
}
function beforeSend(args) {
// Add custom headers
args.ajaxSettings.headers = args.ajaxSettings.headers || {};
args.ajaxSettings.headers['Authorization'] = 'Bearer ' + getToken();
}
</script>视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager"
beforeDelete="beforeDelete"
delete="onDelete"
beforeSend="beforeSend">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>
<script>
function beforeDelete(args) {
console.log('Before delete:', args.fileDetails);
// Validate or prevent deletion
var isReadOnly = args.fileDetails.some(function(f) { return f.isReadOnly; });
if (isReadOnly) {
args.cancel = true;
}
}
function onDelete(args) {
console.log('File deleted:', args.fileDetails);
// Update UI or log action
}
function beforeSend(args) {
// Add custom headers
args.ajaxSettings.headers = args.ajaxSettings.headers || {};
args.ajaxSettings.headers['Authorization'] = 'Bearer ' + getToken();
}
</script>Pattern 8: Virtual Scrolling for Large Datasets
模式8:大型数据集的虚拟滚动
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager"
enableVirtualization="true"
height="600px"
width="100%">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager"
enableVirtualization="true"
height="600px"
width="100%">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>Pattern 9: State Persistence
模式9:状态持久化
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager"
enablePersistence="true">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>
<!-- Persists: view type, current path, selected items -->视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager"
enablePersistence="true">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>
<!-- Persists: view type, current path, selected items -->Pattern 10: Localization and RTL
模式10:本地化与RTL
View Code (Index.cshtml):
html
<ejs-filemanager id="filemanager"
locale="ar-AE"
enableRtl="true">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>视图代码(Index.cshtml):
html
<ejs-filemanager id="filemanager"
locale="ar-AE"
enableRtl="true">
<e-filemanager-ajaxsettings url="/FileManager/FileManager">
</e-filemanager-ajaxsettings>
</ejs-filemanager>Key Properties Summary
关键属性汇总
Essential Configuration:
- - Server communication endpoints (url, uploadUrl, downloadUrl, getImageUrl)
ajaxSettings - - Current directory path
path - /
width- Component dimensionsheight - - Display mode (LargeIcons or Details)
view - - Enable drag-and-drop functionality
allowDragAndDrop - - Enable multiple file selection
allowMultiSelection - - Display image thumbnails
showThumbnail
Upload Settings:
- - Automatically upload files
uploadSettings.autoUpload - - Restrict file types
uploadSettings.allowedExtensions - - Maximum file size limit
uploadSettings.maxFileSize - - Enable folder uploads
uploadSettings.directoryUpload - - Upload files one by one
uploadSettings.sequentialUpload
Customization:
- - Configure toolbar items and visibility
toolbarSettings - - Configure context menu for different contexts
contextMenuSettings - - Configure left sidebar
navigationPaneSettings - - Configure columns in details view
detailsViewSettings - - Configure search behavior
searchSettings
Advanced:
- - Optimize rendering for large lists
enableVirtualization - - Remember user preferences
enablePersistence - - Right-to-left layout support
enableRtl - - Apply custom CSS styling
cssClass - - Display file extensions
showFileExtension - - Show/hide hidden files
showHiddenItems - - Display checkboxes for selection
showItemCheckBoxes
核心配置:
- - 服务端通信端点(url, uploadUrl, downloadUrl, getImageUrl)
ajaxSettings - - 当前目录路径
path - /
width- 组件尺寸height - - 展示模式(大图标或详情视图)
view - - 启用拖拽功能
allowDragAndDrop - - 启用多文件选择
allowMultiSelection - - 展示图片缩略图
showThumbnail
上传设置:
- - 自动上传文件
uploadSettings.autoUpload - - 限制文件类型
uploadSettings.allowedExtensions - - 最大文件大小限制
uploadSettings.maxFileSize - - 启用文件夹上传
uploadSettings.directoryUpload - - 串行上传文件
uploadSettings.sequentialUpload
自定义配置:
- - 配置工具栏项与可见性
toolbarSettings - - 为不同场景配置上下文菜单
contextMenuSettings - - 配置左侧边栏
navigationPaneSettings - - 配置详情视图的列
detailsViewSettings - - 配置搜索行为
searchSettings
高级配置:
- - 优化大型列表的渲染性能
enableVirtualization - - 记住用户偏好设置
enablePersistence - - 支持从右到左布局
enableRtl - - 应用自定义CSS样式
cssClass - - 展示文件扩展名
showFileExtension - - 显示/隐藏隐藏文件
showHiddenItems - - 展示选择复选框
showItemCheckBoxes
Common Use Cases
常见使用场景
Use Case 1: Document Management System
- Users browse uploaded documents by folder
- Search and filter documents by metadata
- Download or preview documents
- Upload new documents with access control
Use Case 2: Image Gallery Manager
- Browse image folders with thumbnail previews
- Drag-and-drop images for organization
- Rename and organize image collections
- Download selected images as ZIP
Use Case 3: Content Administration
- Manage website content folders
- Create and organize folder hierarchies
- Rename and delete content items
- Control user access to specific folders
Use Case 4: Cloud Storage Client
- Full file management operations
- Multi-file upload with progress tracking
- Persistent user preferences across sessions
- Synchronized state
场景1:文档管理系统
- 用户按文件夹浏览上传的文档
- 按元数据搜索和过滤文档
- 下载或预览文档
- 带访问控制的新文档上传
场景2:图片库管理器
- 带缩略图预览的图片文件夹浏览
- 拖拽整理图片
- 重命名和组织图片集合
- 下载选中的图片为ZIP包
场景3:内容管理后台
- 管理网站内容文件夹
- 创建和组织文件夹层级
- 重命名和删除内容项
- 控制用户对特定文件夹的访问权限
场景4:云存储客户端
- 完整的文件管理操作
- 带进度追踪的多文件上传
- 跨会话持久化用户偏好
- 状态同步