Nano Banana Pro
Agent skill for nano-banana-pro
An overview of extensibility file picker prompts.
Sign in to like and favorite skills
File or directory prompts are a simple UI mechanism for prompting the user to select a file or directory path. Prompting the user creates the file dialog from the native OS with custom dialog options to fit the user's specific scenario.
This article covers the following scenarios for working with the file or directory pick prompts:
To create a file open prompt, call the
method from the ShellExtensibility object.ShowOpenFileDialogAsync
The
method takes two parameters:ShowOpenFileDialogAsync
| Parameter | Type | Required | Description |
|---|---|---|---|
| | Yes | Defines the file picker prompt options to customize the dialog. |
| | Yes | The for the async operation. When triggered, the prompt is force-closed. |
If the user closes or cancels the dialog,
ShowOpenFileDialogAsync returns null.
The following code inside a
shows a file prompt with default dialog options.Command
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) { FileDialogOptions options = new(); string? filePath = await this.Extensibility.Shell().ShowOpenFileDialogAsync(options, cancellationToken); }
In some cases, it's useful to enable users to select more than one file at a time, which you can do with the
method.ShowOpenMultipleFilesDialogAsync
The
method takes two parameters:ShowOpenMultipleFilesDialogAsync
| Parameter | Type | Required | Description |
|---|---|---|---|
| | Yes | Defines the file picker prompt options to customize the dialog. |
| | Yes | The for the async operation. When triggered, the prompt is force-closed. |
If the user closes or cancels the dialog,
ShowOpenMultipleFilesDialogAsync returns null.
The following code inside a
shows a file prompt with default dialog options.Command
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) { FileDialogOptions options = new(); IReadOnlyList<string>? filePath = await this.Extensibility.Shell().ShowOpenMultipleFilesDialogAsync(options, cancellationToken); }
Prompting the user for a filename to save with the Save As option allows them to specify a custom filename.
The
method takes two parameters:ShowSaveAsFileDialogAsync
| Parameter | Type | Required | Description |
|---|---|---|---|
| | Yes | Defines the file picker prompt options to customize the dialog. |
| | Yes | The for the async operation. When triggered, the prompt is force-closed. |
If the user closes or cancels the dialog,
ShowSaveAsFileDialogAsync returns null.
The following code inside a
shows a file prompt with default dialog options.Command
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) { FileDialogOptions options = new(); string? filePath = await this.Extensibility.Shell().ShowSaveAsFileDialogAsync(options, cancellationToken); }
To create a file open prompt, call the
method from the ShellExtensibility object.ShowOpenFolderDialogAsync
The
method takes two parameters:ShowOpenFolderDialogAsync
| Parameter | Type | Required | Description |
|---|---|---|---|
| | Yes | Defines the file picker prompt options to customize the dialog. |
| | Yes | The for the async operation. When triggered, the prompt is force-closed. |
If the user closes or cancels the dialog,
ShowOpenFolderDialogAsync returns null.
The following code inside a
shows a file prompt with default dialog options.Command
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) { FolderDialogOptions options = new(); string? folderPath = await this.Extensibility.Shell().ShowOpenFolderDialogAsync(options, cancellationToken); }
You can use the
FileDialogOptions, DialogFilters, and FolderDialogOptions types to customize your prompts.
| Property | Type | Required | Description | Sample |
|---|---|---|---|---|
| | No | The title of the dialog. If the title is an empty string, the system uses a default title, which is either Save As or Open. Default is . | "Open a file" |
| | No | The filename in the input box of the dialog. For the open file dialog, the filename must exist or the dialog returns an error. If an invalid filename is passed, the default is used. Default is . | "filename.ext" |
| | No | The filters used for the dialog. | See Examples of prompts with custom options. |
| Term | Type | Required | Description | Example |
|---|---|---|---|---|
| | Yes | The filters for selecting or saving a file. | See Examples of prompts with custom options. |
| | No | Used to set the default filter index of the filter that's selected by default. Default is . | The minimum index is and the maximum is the . |
| Property | Type | Required | Description | Sample |
|---|---|---|---|---|
| | No | The title of the dialog. If the title is an empty string, the system uses a default title, which is either Save As or Open. Default is . | "Open a file" |
| | No | The directory the dialog should have open, which should be an absolute path. If is an empty string, the initial directory defaults to the last opened directory. If there's no previously opened directory, the initial directory defaults to the root folder. If is specified, a flag is passed in to the dialog to open to the specified directory instead of the last opened directory. If an invalid directory is passed, the default is used. Default is . | "path/to/folder" |
DialogFilter[] filters = new DialogFilter[] { new DialogFilter("Word Files", ".doc", ".docx"), new DialogFilter("Excel Files", ".xls", ".xlsx"), new DialogFilter("All Files", ".*"), }; FileDialogOptions options = new FileDialogOptions() { Title = "Choose a File To Open". InitialDirectory = "absolute/path/to/file", InitialFileName = "file.txt", Filters = new DialogFilters(filters) { DefaultFilterIndex = 1, }, }; string? filePath = await Extensibilty.Shell().ShowOpenFileDialogAsync(options, cancellationToken);
FolderDialogOptions options = new FolderDialogOptions() { Title = "Choose a Folder", InitialDirectory = "absolute/path/to/folder" }; string? folderPath = await Extensibilty.Shell().ShowOpenFolderDialogAsync(options, cancellationToken);