Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FolderPicker class

Applies to Windows and Windows Phone

Represents a UI element that lets the user choose folders.

Syntax


var folderPicker = new Windows.Storage.Pickers.FolderPicker();

Attributes

[Version(0x06020000)]

Members

The FolderPicker class has these types of members:

Constructors

The FolderPicker class has these constructors.

ConstructorDescription
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.

MethodDescription
PickFolderAndContinue Shows the file picker so that the user can pick a folder, deactivating and the app and reactivating it when the operation is complete. (Windows Phone Store app)
PickSingleFolderAsync Shows the folderPicker object so that the user can pick a folder. (Windows Store app)

 

Properties

The FolderPicker class has these properties.

PropertyAccess typeDescription

CommitButtonText

Read/writeGets or sets the label text of the folder picker's commit button.

ContinuationData

Read-onlyGets a set of values to be populated by the app before a PickFolderAndContinue operation that deactivates the app in order to provide context when the app is activated. (Windows Phone Store app)

FileTypeFilter

Read-onlyGets the collection of file types that the folder picker displays.

SettingsIdentifier

Read/writeGets or sets the settings identifier associated with the with the current FolderPicker instance.

SuggestedStartLocation

Read/writeGets or sets the initial location where the folder picker looks for folders to present to the user.

ViewMode

Read/writeGets 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.

To learn about using file pickers in Windows Phone Store apps, see How to continue your Windows Phone app after calling a file picker.

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]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Storage.Pickers
Windows::Storage::Pickers [C++]

Metadata

Windows.winmd

See also

File picker sample
Quickstart: Accessing files with file pickers
How to continue your Windows Phone app after calling a file picker

 

 

Show:
© 2014 Microsoft