FileOpenPicker class
Represents a UI element that lets the user choose and open files.
Syntax
var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
Members
The FileOpenPicker class has these types of members:
Constructors
The FileOpenPicker class has these constructors.
| Constructor | Description |
|---|---|
| FileOpenPicker | Creates a new instance of a FileOpenPicker. |
Methods
The FileOpenPicker class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| PickMultipleFilesAndContinue | Shows the file picker so that the user can pick multiple files, deactivating and the app and reactivating it when the operation is complete. (Windows Phone Store app) |
| PickMultipleFilesAsync | Shows the file picker so that the user can pick multiple files. (Windows Store app) |
| PickSingleFileAndContinue | Shows the file picker so that the user can pick one file, potentially deactivating the app and reactivating it when the operation is complete. (Windows Phone Store app) |
| PickSingleFileAsync | Shows the file picker so that the user can pick one file. |
| PickSingleFileAsync(String) | Shows the file picker so that the user can pick one file. |
| ResumePickSingleFileAsync | Resumes the picking operation to retrieve the user-selected file if the user navigates away from the app after the picker operation has completed and the app is suspended. |
Properties
The FileOpenPicker class has these properties.
| Property | Access type | Description |
|---|---|---|
|
Read/write | Gets or sets the label text of the file open picker's commit button. | |
|
Read-only | Gets a set of values to be populated by the app before PickSingleFileAndContinue or PickMultipleFilesAndContinue operation that deactivates the app in order to provide context when the app is activated. (Windows Phone Store app) | |
|
Read-only | Gets the collection of file types that the file open picker displays. | |
|
Read/write | Gets or sets the settings identifier associated with the state of the file open picker. | |
|
Read/write | Gets or sets the initial location where the file open picker looks for files to present to the user. | |
|
Read/write | Gets or sets the view mode that the file open picker uses to display items. |
Remarks
To get started accessing files and folders file pickers, see Quickstart: Accessing files with file pickers.
To learn about using file pickers in Windows Phone Store apps, see How to continue your Windows Phone app after calling a file picker.
Examples
The File picker sample demonstrates how to check whether the app is snapped, how to set file picker properties, and how to show a file picker so that the user can pick one file.
// Verify that we are currently not snapped, or that we can unsnap to open the picker var currentState = Windows.UI.ViewManagement.ApplicationView.value; if (currentState === Windows.UI.ViewManagement.ApplicationViewState.snapped && !Windows.UI.ViewManagement.ApplicationView.tryUnsnap()) { // Fail silently if we can't unsnap return; } // Create the picker object and set options var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail; openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary; // Users expect to have a filtered view of their folders depending on the scenario. // For example, when choosing a documents folder, restrict the filetypes to documents for your application. openPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]); // Open the picker for the user to pick a file openPicker.pickSingleFileAsync().then(function (file) { if (file) { // Application now has read/write access to the picked file WinJS.log && WinJS.log("Picked photo: " + file.name, "sample", "status"); } else { // The picker was dismissed with no selected file WinJS.log && WinJS.log("Operation cancelled.", "sample", "status"); } });
For C#, the File picker sample demonstrates how to check whether your app is snapped in the EnsureUnsnapped method.
internal bool EnsureUnsnapped() { // FilePicker APIs will not work if the application is in a snapped state. // If an app wants to show a FilePicker while snapped, it must attempt to unsnap first bool unsnapped = ((ApplicationView.Value != ApplicationViewState.Snapped) || ApplicationView.TryUnsnap()); if (!unsnapped) { NotifyUser("Cannot unsnap the sample.", NotifyType.StatusMessage); } return unsnapped; }
The File picker sample also demonstrates how to show a file picker so that the user can pick multiple files.
openPicker.pickMultipleFilesAsync().then(function (files) { if (files.size > 0) { // Application now has read/write access to the picked file(s) var outputString = "Picked files:\n"; for (var i = 0; i < files.size; i++) { outputString = outputString + files[i].name + "\n"; } WinJS.log && WinJS.log(outputString, "sample", "status"); } else { // The picker was dismissed with no selected file WinJS.log && WinJS.log("Operation cancelled.", "sample", "status"); } });
Requirements (Windows 10 device family)
| |
|
API contract |
|
|
Namespace |
|
|
Metadata |
|
Requirements (Windows 8.x and Windows Phone 8.x)
|
Minimum supported client |
Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server |
Windows Server 2012 [Windows Store apps only] |
|
Minimum supported phone |
Windows Phone 8 |
|
Namespace |
|
|
Metadata |
|
Attributes
- [Muse()]
- [Version(0x06020000)]
See also
- Object
- File picker sample
- Quickstart: Accessing files with file pickers
- How to continue your Windows Phone app after calling a file picker

