# FileSelect Events

This article describes the events and event arguments of the Telerik FileSelect for Blazor:

* [`OnSelect` event](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#onselect)
* [`OnRemove` event](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#onremove)
* [`FileSelectFileInfo` class](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#fileselectfileinfo)

## FileSelectFileInfo

The FileSelect event handlers provide a [`FileSelectEventArgs` argument](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.fileselecteventargs). `FileSelectEventArgs` has a `Files` property, which is a `List<FileSelectFileInfo>` type.

The `FileSelectFileInfo` type contains the following properties:

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Property             | Type             | Description                                                                                                                                                                                                                                                                                                                                         |
| -------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Id`                 | `string`         | The unique file identifier.                                                                                                                                                                                                                                                                                                                         |
| `Name`               | `string`         | The encoded file name, including the extension. One method to decode it is [`System.Net.WebUtility.HtmlDecode()`](https://learn.microsoft.com/en-us/dotnet/api/system.net.webutility.htmldecode). The file can be renamed in the [`OnSelect` event handler](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#onselect). |
| `Size`               | `long`           | The file size in bytes.                                                                                                                                                                                                                                                                                                                             |
| `Extension`          | `string`         | The file extension.                                                                                                                                                                                                                                                                                                                                 |
| `InvalidExtension`   | `bool`           | A Boolean flag that shows if the file type is invalid.                                                                                                                                                                                                                                                                                              |
| `InvalidMinFileSize` | `bool`           | A Boolean flag that shows if file size is below the minimum.                                                                                                                                                                                                                                                                                        |
| `InvalidMaxFileSize` | `bool`           | A Boolean flag that shows if the file size exceeds the maximum.                                                                                                                                                                                                                                                                                     |
| `Stream`             | `FileInfoStream` | A [`System.IO.Stream`](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream) that can be used to load the file to memory, file system, or other. Used for **asynchronously** getting the file contents as a byte array.                                                                                                                     |

> Due to the Blazor framework limitations, `FileInfoStream` does not support **synchronous** operations such as `Read`, `Seek`, `Flush`, and `Write`. The methods exist, but will [throw an exception](https://www.telerik.com/blazor-ui/documentation/knowledge-base/fileselect-stream-exception). A possible workaround is to copy the `FileInfoStream` **asynchronously** to another `Stream` with `CopyToAsync`, as demonstrated by the `OnSelect` event example below.

## OnSelect

The `OnSelect` event fires each time when the user selects file(s) through the **Select Files** button or by drag and drop anywhere in the component.

The event handler receives a [`FileSelectEventArgs` object](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#fileselectfileinfo). If you set its `IsCancelled` property to `true`, the component ignores the user action and all newly selected files do not appear in the component file list.

`OnSelect` fires for both valid and invalid files. You can verify if the file is valid by checking the validation-related properties of each [`FileSelectFileInfo`](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#fileselectfileinfo) object. If necessary, the application can still handle invalid files, for example, read their content.

See the [example below](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#example).

## OnRemove

The `OnRemove` event fires when the user deletes a file from the list by clicking the **x** icon or by pressing the `Del` key.

The event handler receives a [`FileSelectEventArgs` object](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#fileselectfileinfo). The `Files` collection in the event argument always contains a single `FileSelectFileInfo` object. This is unlike the `OnSelect` event where `Files` can include one or more files.

`OnRemove` fires for both valid and invalid files.

## Example

> caption Handle the FileSelect `OnSelect` and `OnRemove` events

<demo metaUrl="client/fileselect/events/" height="300"></demo>

> tip The event is an `EventCallback`. It can be synchronous and return `void`, or asynchronous and return `async Task`. Do not use `async void`.

## See Also

* [Live Demo: Blazor FileSelect Events](https://demos.telerik.com/blazor-ui/fileselect/events)
* [Telerik UI for Blazor FileSelect Overview](https://www.telerik.com/blazor-ui/documentation/components/fileselect/overview)
* [Blazor FileSelect Validation](https://www.telerik.com/blazor-ui/documentation/components/fileselect/validation)
