4 out of 16 rated this helpful - Rate this topic

FileOpenPicker class

Applies to Windows and Windows Phone

Represents a UI element that lets the user choose and open files.

Syntax


public ref class FileOpenPicker sealed 

Attributes

[Muse()]
[Version(0x06020000)]

Members

The FileOpenPicker class has these types of members:

Constructors

The FileOpenPicker class has these constructors.

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

MethodDescription
PickMultipleFilesAsync Shows the file picker so that the user can pick multiple files.
PickSingleFileAsync

 

Properties

The FileOpenPicker class has these properties.

PropertyAccess typeDescription

CommitButtonText

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

FileTypeFilter

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

SettingsIdentifier

Read/writeGets or sets the settings identifier associated with the state of the file open picker.

SuggestedStartLocation

Read/writeGets or sets the initial location where the file open picker looks for files to present to the user.

ViewMode

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

Important  In Windows 8 if you attempt to display 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. Note that Windows 8.1 does not define a specific snapped window size. Instead, users can resize apps to any width, down to the minimum. Therefore, if your app will deploy only on Windows 8.1, you can ignore the EnsureUnsnapped function and calls to it in this topic's example code.

Windows Phone 8

This API is supported in native apps only.

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.

No code example is currently available or this language may not be supported.

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.

Note  You should always make sure that your app is not snapped (or that it can be unsnapped) and set file picker properties regardless of whether the user is picking a single file or multiple files.

No code example is currently available or this language may not be supported.

You can also use file picker on Windows Phone. The following shows a C++ example. On Windows Phone, FileOpenPicker is supported in native apps only.


FileOpenPicker^ openPicker = ref new FileOpenPicker(); 
openPicker->ViewMode = PickerViewMode::Thumbnail; 
openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary; 
openPicker->FileTypeFilter->Append("*"); 
   
create_task(openPicker->PickSingleFileAsync()).then([this](StorageFile^ file) 
{
    if (file) 
    { 
        m_PickedFileName = file->Name; 
    } 
    else 
    { 
        // Operation cancelled.
    } 
});


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

Namespace

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

Metadata

Windows.winmd

See also

File picker sample
Quickstart: Accessing files with file pickers

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.