# FileManager Context Menu

The ContextMenu of the FileManager enables you to easily execute commands on the selected file or folder.

The component uses the Telerik UI for [Blazor ContextMenu](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/overview) and provides the following commands:

* [Rename](https://www.telerik.com/blazor-ui/documentation/components/filemanager/context-menu#rename)
* [Download](https://www.telerik.com/blazor-ui/documentation/components/filemanager/context-menu#download)
* [Delete](https://www.telerik.com/blazor-ui/documentation/components/filemanager/context-menu#delete)

## Rename

The `Rename` command of the FileManager ContextMenu allows renaming the selected file or folder. Users can rename one item at a time - the one they open the ContextMenu for.

Clicking the command will fire the [`OnEdit`](https://www.telerik.com/blazor-ui/documentation/components/filemanager/events#onedit) event. An input with the file/folder name will be rendered, so the user can edit it. Pressing `Enter` or blurring the input will fire the [`OnUpdate`](https://www.telerik.com/blazor-ui/documentation/components/filemanager/events#onupdate) event allowing you can handle the name update of the actual item in your data source.

When an item is renamed, make sure to also update its `Path`. Renaming a directory that has children will require updating their `Path` as well. If the actual file system is modified, then this will be handled out of the box.

## Download

The `Download` command of the FileManager ContextMenu allows downloading of the selected file.

Clicking the command will fire the [`OnDownload`](https://www.telerik.com/blazor-ui/documentation/components/filemanager/events#ondownload) event, so you can handle the actual download.

The component does not have the actual files, so the `Item` field of the `FileManagerDownloadEventArgs` just provide metadata of the selected file. Based on that, you should find the actual in the file system you are using and provide the following data to the arguments, so the download can be performed:

* `args.Stream` - the `MemoryStream` of the actual selected file.
* `args.MimeType` - the `MimeType` of the actual file, e.g. "image/png".

In addition, you can also provide a custom file name through the `FileName` field of the `FileManagerDownloadEventArgs`.

## Delete

The `Delete` command of the FileManager ContextMenu allows deleting of the selected files. Multiple file deletion is supported. It does not matter which item the ContextMenu for, the `Delete` command will handle the deletion of all selected files.

Clicking the command will open a delete confirmation dialog. Pressing the `OK` button will fire the [`OnDelete`](https://www.telerik.com/blazor-ui/documentation/components/filemanager/events#ondelete) event, so you can handle the deletion of the actual files in the data source. Pressing the `Cancel` button will close the dialog and prevent the deletion.

## Customization

Configure the context menu through the `FileManagerContextMenuSettings` tag and its `Data` parameter. Provide a collection of `FileManagerContextMenuItem` objects, and assign each item's `CommandName` to one of the following [FileManagerCommands](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.filemanagercommands) string values to retain the built-in FileManager behavior:

* `FileManagerCommands.Rename`
* `FileManagerCommands.Download`
* `FileManagerCommands.Delete`

A custom `CommandName` value triggers the [`OnClick`](https://www.telerik.com/blazor-ui/documentation/components/filemanager/events#onclick) event of `FileManagerContextMenuSettings`, where you can implement the required action. The FileManager [`OnContextMenu`](https://www.telerik.com/blazor-ui/documentation/components/filemanager/events#oncontextmenu) event lets you provide different menu items for each file or folder. To prevent the menu from opening for a specific item, set `args.IsCancelled` to `true`.

> caption The following example defines custom commands, changes the available commands by item type, and disables the context menu for a specific file.

<demo metaUrl="client/filemanager/context-menu/customization/" height="570"></demo>

# Example

The following example demonstrates handling of the ContextMenu commands.

<demo metaUrl="client/filemanager/context-menu/example-1/" height="570"></demo>

## See Also

* [Live Demo: FileManager](https://demos.telerik.com/blazor-ui/filemanager/overview)
* [FileManager Events](https://www.telerik.com/blazor-ui/documentation/components/filemanager/events)
