Skip to content

FileChooser

Namespace: PuppeteerSharp

public class FileChooser

FileChooser objects are returned via the WaitForFileChooserAsync(WaitForOptions) method. File choosers let you react to the page requesting for a file.

Inheritance: object

In browsers, only one file chooser can be opened at a time. All file choosers must be accepted or canceled. Not doing so will prevent subsequent file choosers from appearing.

Example

var waitTask = page.WaitForFileChooserAsync();
await Task.WhenAll(
waitTask,
page.ClickAsync("#upload-file-button")); // some button that triggers file selection
await waitTask.Result.AcceptAsync('/tmp/myfile.pdf');

View source

public bool IsMultiple { get; }

Whether file chooser allow for <a href=“https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-multiple"&gt;multiple&lt;/a> file selection.

Value: bool

View source

public Task AcceptAsync(params string[] filePaths)

Accept the file chooser request with given paths. If some of the filePaths are relative paths, then they are resolved relative to the current working directory.

Parameters

Name Type Description
filePaths string[] File paths to send to the file chooser.

Returns: Task — A task that resolves after the accept message is processed by the browser.

View source

public Task CancelAsync()

Closes the file chooser without selecting any files.

Returns: Task — A task that resolves after the cancel event is sent to the browser.

View source

Made with love by Dario Kondratiuk