Represents a UI element that lets the user choose folders.
Syntax
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- VersionAttribute(NTDDI_WIN8)
Members
The FolderPicker class has these types of members:
Constructors
The FolderPicker class has these constructors.
| Constructor | Description |
|---|---|
| FolderPicker | Creates a new instance of a FolderPicker. |
Methods
The FolderPicker class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| PickSingleFolderAsync | Shows the folderPicker object so that the user can pick a folder. |
Properties
The FolderPicker class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read/write | Gets or sets the label text of the folder picker's commit button. | |
| Read-only | Gets the collection of file types that the folder picker displays. | |
| Read/write | Gets or sets the settings identifier associated with the with the current FolderPicker instance. | |
| Read/write | Gets or sets the initial location where the folder picker looks for folders to present to the user. | |
| Read/write | Gets or sets the view mode that the folder picker uses to display items. |
Remarks
To get started accessing files and folders file pickers, see Quickstart: Accessing files with file pickers.
Warning If you try to show the file picker while your app is snapped the file picker will not be shown and an exception will be thrown. You can avoid this by making sure your app is not snapped or by unsnapping it before you call the file picker. The following code examples and the File picker sample show you how.
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 a folder for the app to access.
// 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 folderPicker = new Windows.Storage.Pickers.FolderPicker; folderPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.desktop; // 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. folderPicker.fileTypeFilter.replaceAll([".docx", ".xlsx", ".pptx"]); folderPicker.pickSingleFolderAsync().then(function (folder) { if (folder) { // Application now has read/write access to all contents in the picked folder (including sub-folder contents) // Cache folder so the contents can be accessed at a later time Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.addOrReplace("PickedFolderToken", folder); WinJS.log && WinJS.log("Picked folder: " + folder.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; }
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 2/25/2013