FileChooser
Namespace: PuppeteerSharp
public class FileChooserFileChooser 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');Properties
Section titled “Properties”IsMultiple
Section titled “IsMultiple”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">multiple</a> file selection.
Value: bool
Methods
Section titled “Methods”AcceptAsync(params string[])
Section titled “AcceptAsync(params string[])”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.
CancelAsync()
Section titled “CancelAsync()”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.
Made with love by Dario Kondratiuk