File Upload
A drop zone that opens the file picker and lists the files you picked.
Installation
bash
shellui-native add file-upload
Platforms: MAUI · Avalonia. Also installs icon.
Usage
Basic
<ui:FileUpload Multiple="True" MaxFiles="5" FilesChanged="OnFilesChanged" /><ui:FileUpload Multiple="True" MaxFiles="5" FilesChanged="OnFilesChanged" />Not available on yet
Tapping the zone opens the platform file picker. The picked files are listed underneath, each with a × to remove it. Without Multiple, a new pick replaces the file.
Reading the files
FilesChanged passes the current list. Open each file as a stream:
csharp
private async void OnFilesChanged(object? sender, IReadOnlyList<FileResult> files)
{
foreach (var file in files)
{
await using var stream = await file.OpenReadAsync();
// upload or read the stream
}
}
csharp
private async void OnFilesChanged(object? sender, IReadOnlyList<IStorageFile> files)
{
foreach (var file in files)
{
await using var stream = await file.OpenReadAsync();
// upload or read the stream
}
}
Limiting the file types
FileTypes takes the platform's own picker type, so set it in code:
csharp
Upload.FileTypes = FilePickerFileType.Images;
csharp
Upload.FileTypes = new[] { FilePickerFileTypes.ImageAll };
MAUI and Avalonia
- Files are
FileResulton MAUI andIStorageFileon Avalonia. - Dropping files on the zone works on Windows only on MAUI, and wherever Avalonia supports drag and drop on Avalonia.
- On Avalonia the zone is a tab stop: Enter or Space opens the picker.
API
| Property | Type | Default | Description |
|---|---|---|---|
Text |
string |
"Drag and drop or click here to upload files" |
Prompt shown in the drop zone. |
Multiple |
bool |
false |
More than one file can be picked; new picks are added to the list. |
MaxFiles |
int |
0 |
The most files the list holds when Multiple is on; 0 for no limit. |
FileTypes |
FilePickerFileType (MAUI) · IReadOnlyList<FilePickerFileType>? (Avalonia) |
null |
Which files the picker offers; null offers every file. Set it in code. |
ShowFiles |
bool |
true |
Lists the picked files under the drop zone. |
| Event | Arguments | Description |
|---|---|---|
FilesChanged |
IReadOnlyList<FileResult> (MAUI) · IReadOnlyList<IStorageFile> (Avalonia) |
The list of files changed; passes the current list. |
| Method | Description |
|---|---|
PickAsync() |
Opens the platform file picker and adds what was picked. |
Add(IEnumerable<FileResult> files) |
Adds files as a pick or a drop would. |
Remove(FileResult file) |
Removes one file from the list. |
Clear() |
Removes every file. |