Skip to content

Commit 51b7274

Browse files
authored
docs(fileselect, upload): add initial files documentation (#1531)
* docs(fileselect, upload): add initial files documentation
1 parent 040f947 commit 51b7274

File tree

4 files changed

+181
-0
lines changed

4 files changed

+181
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Initial Files
3+
page_title: FileSelect Initial Files
4+
description: The FileSelect allows you to define a collection of pre-selected files, which will be initially shown in the selected file list.
5+
slug: fileselect-initial-files
6+
tags: telerik,blazor,fileselect,initial, files
7+
published: True
8+
position: 40
9+
---
10+
11+
# FileSelect Initial Files
12+
13+
The Blazor FileSelect component enables you to display specific files in the file list when the component loads for the first time. This is a convenient way to show previously uploaded files.
14+
15+
To configure the initially displayed files, use the `Files` parameter of the FileSelect—it accepts an `IEnumerable<FileSelectFileInfo>` collection that stores a set of pre-selected files.
16+
17+
>caption Display initial files in FileSelect's list.
18+
19+
```CSHTML
20+
21+
<TelerikFileSelect Files="@InitialFiles" />
22+
23+
@code {
24+
private List<FileSelectFileInfo> InitialFiles { get; set; } = new List<FileSelectFileInfo>()
25+
{
26+
new FileSelectFileInfo(){ Id="1", Name="Report", Extension=".pdf", Size = 1024 * 1024 * 2 },
27+
new FileSelectFileInfo(){ Id="2", Name="Image", Extension=".jpg", Size = 1024 * 1024 * 4 },
28+
new FileSelectFileInfo(){ Id="3", Name="Picture", Extension=".png", Size = 1024 * 1024 * 3 },
29+
};
30+
}
31+
32+
```
33+
34+
## Persist Selected Files
35+
36+
The Initial Files feature of the FileSelect allows you to save a list of files that the user has selected. Then, you can display them again when the page is reloaded. To achieve this:
37+
1. Store the [`FileSelectFileInfo`]({%slug fileselect-events%}#fileselectfileinfo) records received during the [`OnSelect`]({%slug fileselect-events%}#onselect) event.
38+
1. Load the [`FileSelectFileInfo`]({%slug fileselect-events%}#fileselectfileinfo) records in the FileSelect when the page is loaded.
39+
40+
>caption How to load files and display them initially in the FileSelect
41+
42+
```CSHTML
43+
44+
@using System.IO;
45+
46+
@if (InitialFiles != null)
47+
{
48+
<TelerikFileSelect Files="@InitialFiles"
49+
OnSelect="@OnSelect" />
50+
}
51+
52+
@code {
53+
private List<FileSelectFileInfo> InitialFiles { get; set; }
54+
55+
private void OnSelect(FileSelectEventArgs args)
56+
{
57+
foreach (var file in args.Files)
58+
{
59+
//await SaveFileInfo(file); Here, you can store the file information it in a database, text file, or any other desired storage
60+
}
61+
}
62+
63+
protected override async Task OnInitializedAsync()
64+
{
65+
await LoadFiles();
66+
}
67+
68+
private async Task LoadFiles()
69+
{
70+
//Simulate files information loading
71+
await Task.Delay(1000);
72+
InitialFiles = new List<FileSelectFileInfo>()
73+
{
74+
new FileSelectFileInfo(){ Id="1", Name="Report", Extension=".pdf", Size = 1024 * 1024 * 2 }
75+
};
76+
}
77+
}
78+
79+
```
80+
81+
82+
## See Also
83+
84+
* [FileSelect API](/blazor-ui/api/Telerik.Blazor.Components.TelerikFileSelect)
85+
* [FileSelect Overview]({%slug fileselect-overview%})

components/fileselect/overview.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Additionally, you may define an external drop zone by using the [Telerik UI for
6969

7070
The FileSelect includes [built-in client-side validation]({%slug fileselect-validation%}) for the file size and type (extension). Additional custom validation can take place in the [OnSelect event]({%slug fileselect-events%}#onselect).
7171

72+
## Initial Files
73+
74+
The Initial Files feature allows you to display a set of pre-selected files in the FileSelect when the component loads. This functionality is helpful when you want to show files that were previously provided by the user. [Read more about the FileSelect Initial Files feature...]({%slug fileselect-initial-files%})
75+
7276
## Templates
7377

7478
You can use the functionality of the built-in template and modify the appearance of the **Select files...** button. [Read more about the Telerik FileSelect templates...]({%slug fileselect-templates%})
@@ -91,6 +95,7 @@ The following table lists the FileSelect parameters. Also check the [FileSelect
9195
| `MinFileSize` | `int?` | Sets the minimum allowed file size in bytes. Read more at [Validation]({%slug fileselect-validation%}). |
9296
| `MaxFileSize`| `int?` | Sets the maximum allowed file size in bytes. Read more at [Validation]({%slug fileselect-validation%}). |
9397
| `Multiple` | `bool`<br />(`true`) | Sets if the user can select several files at the same time. |
98+
| `Files` | `IEnumerable<FileSelectFileInfo>` | Collection of files that will be initially displayed in the FileSelect file list. |
9499

95100

96101
## FileSelect Reference and Methods

components/upload/initial-files.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Initial Files
3+
page_title: Upload Initial Files
4+
description: The Upload allows you to define a collection of pre-selected files, which will be initially shown in the selected file list.
5+
slug: upload-initial-files
6+
tags: telerik,blazor,upload,initial, files
7+
published: True
8+
position: 40
9+
---
10+
11+
# Upload Initial Files
12+
13+
The Blazor Upload component enables you to display specific files in the file list when the component loads for the first time. This is a convenient way to show previously uploaded files.
14+
15+
To configure the initially displayed files, use the `Files` parameter of the Upload—it accepts an `IEnumerable<UploadFileInfo>` collection that stores a set of pre-selected files.
16+
17+
>caption Display initial files in Upload's list.
18+
19+
```CSHTML
20+
21+
<TelerikUpload Files="@InitialFiles" />
22+
23+
@code {
24+
private List<UploadFileInfo> InitialFiles { get; set; } = new List<UploadFileInfo>()
25+
{
26+
new UploadFileInfo(){ Id="1", Name="Report", Extension=".pdf", Size = 1024 * 1024 * 2 },
27+
new UploadFileInfo(){ Id="2", Name="Image", Extension=".jpg", Size = 1024 * 1024 * 4 },
28+
new UploadFileInfo(){ Id="3", Name="Picture", Extension=".png", Size = 1024 * 1024 * 3 },
29+
};
30+
}
31+
32+
```
33+
34+
## Persist Selected Files
35+
36+
The Initial Files feature of the Upload allows you to save a list of files that the user has selected. Then, you can display them again when the page is reloaded. To achieve this:
37+
1. Store the [`UploadFileInfo`]({%slug upload-events%}#uploadfileinfo) records received during the [`OnSelect`]({%slug upload-events%}#onselect) event.
38+
1. Load the [`UploadFileInfo`]({%slug upload-events%}#uploadfileinfo) records in the Upload when the page is loaded.
39+
40+
>caption How to load files and display them initially in the Upload
41+
42+
```CSHTML
43+
44+
@using System.IO;
45+
46+
47+
@if (InitialFiles != null)
48+
{
49+
<TelerikUpload Files="@InitialFiles"
50+
OnSelect="@OnSelect" />
51+
}
52+
53+
@code {
54+
private List<UploadFileInfo> InitialFiles { get; set; }
55+
56+
private void OnSelect(UploadSelectEventArgs args)
57+
{
58+
foreach (var file in args.Files)
59+
{
60+
//await SaveFileInfo(file); Here, you can store the file information it in a database, text file, or any other desired storage
61+
}
62+
}
63+
64+
protected override async Task OnInitializedAsync()
65+
{
66+
await LoadFiles();
67+
}
68+
69+
private async Task LoadFiles()
70+
{
71+
//Simulate files information loading
72+
await Task.Delay(1000);
73+
InitialFiles = new List<UploadFileInfo>()
74+
{
75+
new UploadFileInfo(){ Id="1", Name="Report", Extension=".pdf", Size = 1024 * 1024 * 2 }
76+
};
77+
}
78+
}
79+
80+
```
81+
82+
83+
## See Also
84+
85+
* [Upload API](/blazor-ui/api/Telerik.Blazor.Components.TelerikUpload)
86+
* [Upload Overview]({%slug upload-overview%})

components/upload/overview.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ Authentication and authorization depends on the application.
175175

176176
The Upload includes [built-in client-side validation]({%slug upload-validation%}) for the file size and type (extension). Additional custom validation can take place in the [OnSelect event]({%slug upload-events%}#onselect).
177177

178+
## Initial Files
179+
180+
The Initial Files feature allows you to display a set of pre-selected files in the Upload when the component loads. This functionality is helpful when you want to show files that were previously provided by the user. [Read more about the Upload Initial Files feature...]({%slug upload-initial-files%})
181+
178182
## Templates
179183

180184
You can use the functionality of the built-in template and modify the appearance of the **Select files...** button. [Read more about the Telerik Upload templates...]({%slug upload-templates%})
@@ -215,6 +219,7 @@ The following table lists the Upload parameters. Also check the [Upload API Refe
215219
| `SaveField` | `string`<br />(`"files"`) | Sets the `FormData` key, which contains the file submitted to the [`SaveUrl` endpoint](#implement-controller-methods). The `SaveField` value must match the save controller method's argument name. |
216220
| `SaveUrl` | `string` | The URL which receives the uploaded files. `SaveUrl` and `RemoveUrl` **cannot change** between file selection and file upload, because the component will be recreated and the selected files will be lost. |
217221
| `WithCredentials` | `bool` | Controls if the Upload will send credentials such as cookies or HTTP headers for [**cross-site** requests](#cross-origin-requests). See [XMLHttpRequest.withCredentials](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials). On the other hand, use the [`OnUpload` and `OnRemove` events]({%slug upload-events%}) to add authentication tokens and other metadata to the component requests. |
222+
| `Files` | `IEnumerable<UploadFileInfo>` | Collection of files that will be initially displayed in the Upload file list. |
218223

219224

220225
## Upload Reference and Methods

0 commit comments

Comments
 (0)