Skip to content

Commit 3c08b42

Browse files
Merge branch 'development' into 984330-AI-Prompt
2 parents 646e699 + a6ceb1b commit 3c08b42

8 files changed

+178
-0
lines changed

blazor-toc.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,7 @@
29812981
<li> <a href="/blazor/file-upload/chunk-upload">Chunk Upload</a></li>
29822982
<li> <a href="/blazor/file-upload/localization">Localization</a></li>
29832983
<li> <a href="/blazor/file-upload/file-source">File Source</a></li>
2984+
<li> <a href="/blazor/file-upload/drag-and-drop">Drag and Drop</a></li>
29842985
<li> <a href="/blazor/file-upload/template">Template</a></li>
29852986
<li> <a href="/blazor/file-upload/validation">Validation</a></li>
29862987
<li> <a href="/blazor/file-upload/form-integration">Form Integration</a></li>
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
layout: post
3+
title: Drag and Drop in Blazor File Upload Component | Syncfusion
4+
description: Learn about drag-and-drop file selection, configuring an external drop area, and related behaviors in the Syncfusion Blazor File Upload component.
5+
platform: Blazor
6+
control: File Upload
7+
documentation: ug
8+
---
9+
10+
# Drag and drop in Blazor File Upload Component
11+
12+
The File Upload component supports drag-and-drop file selection. Users can drag files from the file explorer and drop them into the drop area. By default, the File Upload component acts as the drop area. The drop area is highlighted when files are dragged over it to indicate that dropping is supported.
13+
14+
## Custom DropArea
15+
16+
The File Upload component allows configuring an external target element as the drop area by using the [DropArea](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Inputs.UploaderModel.html#Syncfusion_Blazor_Inputs_UploaderModel_DropArea) property. The element can be specified as an HTML element reference or by using the element’s ID.
17+
18+
```cshtml
19+
@using Syncfusion.Blazor.Inputs
20+
21+
<div ID="DropArea">
22+
Drop files here to upload
23+
</div>
24+
25+
<SfUploader ID="UploadFiles" AutoUpload="false" DropArea="#DropArea">
26+
</SfUploader>
27+
28+
<style>
29+
#DropArea {
30+
padding: 50px 25px;
31+
margin: 30px auto;
32+
border: 1px solid #c3c3c3;
33+
text-align: center;
34+
width: 100%;
35+
display: inline-flex;
36+
}
37+
38+
.e-file-select,
39+
.e-file-drop {
40+
display: none;
41+
}
42+
43+
body .e-upload-drag-hover {
44+
outline: 2px dashed brown;
45+
}
46+
47+
#uploadfile {
48+
width: 60%;
49+
display: inline-flex;
50+
margin-left: 5%;
51+
}
52+
</style>
53+
```
54+
55+
{% previewsample "https://blazorplayground.syncfusion.com/embed/BZLoiZrPzKWARfzw?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
56+
![Customizing Drop Area in Blazor FileUpload](./images/blazor-fileupload-drop-area-customization.gif)
57+
58+
## DropEffect
59+
60+
The File Upload exposes a DropEffect property that controls the cursor feedback and allowed drop operation during drag-and-drop. Set this property to Default, Copy, Move, Link, or None. Default uses the browser’s behavior. Dropped files are added to the selected files list and processed according to component settings (for example, AutoUpload, SaveUrl/RemoveUrl, AllowedExtensions, MinFileSize, and MaxFileSize).
61+
62+
### Copy
63+
64+
Shows a copy cursor during drag-and-drop. Dropped files are added to the File Upload’s selection without modifying the originals. File Upload proceeds based on the component configuration.
65+
66+
```cshtml
67+
68+
@using Syncfusion.Blazor.Inputs
69+
70+
<SfUploader ID="UploadFiles" AutoUpload="false" DropEffect="DropEffect.Copy">
71+
<UploaderEvents FileSelected="onFileSelect"></UploaderEvents>
72+
</SfUploader>
73+
74+
@code{
75+
private void onFileSelect(SelectedEventArgs args)
76+
{
77+
// here you can get dropped file data
78+
}
79+
}
80+
81+
```
82+
83+
{% previewsample "https://blazorplayground.syncfusion.com/embed/LZroMDBPfgwxYYBv?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
84+
![Copy drop effect in Blazor FileUpload](./images/blazor-fileupload-drag-and-drop-copy.gif)
85+
86+
### Move
87+
88+
Shows a move cursor during drag-and-drop. Source files are not moved from their original location; the File Upload only adds them to the selection and uploads according to configuration.
89+
90+
```cshtml
91+
92+
@using Syncfusion.Blazor.Inputs
93+
94+
<SfUploader ID="UploadFiles" AutoUpload="false" DropEffect="DropEffect.Move">
95+
<UploaderEvents FileSelected="onFileSelect"></UploaderEvents>
96+
</SfUploader>
97+
98+
@code{
99+
private void onFileSelect(SelectedEventArgs args)
100+
{
101+
// here you can get dropped file data
102+
}
103+
}
104+
105+
```
106+
107+
{% previewsample "https://blazorplayground.syncfusion.com/embed/hjBICXBPfzZPgIvh?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
108+
![Move drop effect in Blazor FileUpload](./images/blazor-fileupload-drop-area-move.gif)
109+
110+
### Link
111+
112+
Shows a link cursor during drag-and-drop. This changes the cursor feedback only; upload behavior remains unchanged.
113+
114+
```cshtml
115+
116+
@using Syncfusion.Blazor.Inputs
117+
118+
<SfUploader ID="UploadFiles" AutoUpload="false" DropEffect="DropEffect.Link">
119+
<UploaderEvents FileSelected="onFileSelect"></UploaderEvents>
120+
</SfUploader>
121+
122+
@code{
123+
private void onFileSelect(SelectedEventArgs args)
124+
{
125+
// here you can get dropped file data
126+
}
127+
}
128+
129+
```
130+
131+
{% previewsample "https://blazorplayground.syncfusion.com/embed/rjBIsDLFJfLAjrAD?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
132+
![Link drop effect in Blazor FileUpload](./images/blazor-fileupload-drop-area-link.gif)
133+
134+
### None
135+
136+
Prevents dropping files on the File Upload or the configured drop area. Use this when disabling drops is required regardless of validation rules.
137+
138+
```cshtml
139+
140+
@using Syncfusion.Blazor.Inputs
141+
142+
<SfUploader ID="UploadFiles" AutoUpload="false" DropEffect="DropEffect.None">
143+
<UploaderEvents FileSelected="onFileSelect"></UploaderEvents>
144+
</SfUploader>
145+
146+
@code{
147+
private void onFileSelect(SelectedEventArgs args)
148+
{
149+
// here you can get dropped file data
150+
}
151+
}
152+
153+
```
154+
155+
{% previewsample "https://blazorplayground.syncfusion.com/embed/LjrosDhbppKYbVqC?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
156+
![None drop effect in Blazor FileUpload](./images/blazor-fileupload-drop-area-none.gif)
157+
158+
## Clipboard Paste
159+
160+
The File Upload component supports file selection through clipboard paste operations. Click on the File Upload element and press Ctrl+V to paste files from the clipboard. The pasted files are added to the selected files list.
161+
162+
```cshtml
163+
@using Syncfusion.Blazor.Inputs
164+
165+
<SfUploader ID="UploadFiles" AutoUpload="false">
166+
<UploaderEvents FileSelected="onFileSelect"></UploaderEvents>
167+
</SfUploader>
168+
169+
@code{
170+
private void onFileSelect(SelectedEventArgs args)
171+
{
172+
// Access pasted file data here
173+
}
174+
}
175+
```
176+
{% previewsample "https://blazorplayground.syncfusion.com/embed/BtBysXhPpSVDXqxx?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
177+
![Clipboard paste file handling in Blazor File Upload component](./images/blazor-fileupload-clipboard-paste.gif)
185 KB
Loading
68 KB
Loading
38.2 KB
Loading
89.4 KB
Loading
64.6 KB
Loading
67.9 KB
Loading

0 commit comments

Comments
 (0)