FileOpenPicker 클래스

정의

사용자가 파일을 선택하고 열 수 있는 UI 요소를 나타냅니다.

데스크톱 앱에서 UI를 표시하는 방식으로 이 클래스의 인스턴스를 사용하기 전에 개체를 소유자의 창 핸들과 연결해야 합니다. 자세한 정보 및 코드 예제는 CoreWindow에 의존하는 WinRT UI 개체 표시를 참조하세요.

public ref class FileOpenPicker sealed
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class FileOpenPicker final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class FileOpenPicker final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class FileOpenPicker final
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class FileOpenPicker
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class FileOpenPicker
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class FileOpenPicker
function FileOpenPicker()
Public NotInheritable Class FileOpenPicker
상속
Object Platform::Object IInspectable FileOpenPicker
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

파일 선택기 샘플에서는 앱이 스냅되었는지 여부, 파일 선택기 속성을 설정하는 방법 및 사용자가 하나의 파일을 선택할 수 있도록 파일 선택기를 표시하는 방법을 보여 줍니다.

FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");

StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
    // Application now has read/write access to the picked file
    OutputTextBlock.Text = "Picked photo: " + file.Name;
}
else
{
    OutputTextBlock.Text = "Operation cancelled.";
}
// 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");
    }
});
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;
}

참고

앱이 스냅되지 않았는지(또는 스냅 해제될 수 있는지) 항상 확인하고 사용자가 단일 파일 또는 여러 파일을 선택하는지 여부에 관계없이 파일 선택기 속성을 설정해야 합니다.

IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
if (files.Count > 0)
{
    StringBuilder output = new StringBuilder("Picked files:\n");
    // Application now has read/write access to the picked file(s)
    foreach (StorageFile file in files)
    {
        output.Append(file.Name + "\n");
    }
    OutputTextBlock.Text = output.ToString();
}
else
{
    OutputTextBlock.Text = "Operation cancelled.";
}
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");
    }
});

설명

파일 및 폴더 파일 선택기 액세스를 시작하려면 빠른 시작: 파일 선택기를 사용하여 파일 액세스를 참조하세요.

UWP 앱 외부에서 이 API를 사용하는 방법에 대한 자세한 내용은 .NET 앱에서 interop API 호출을 참조하세요.

버전 기록

Windows 버전 SDK 버전 추가된 값
1903 18362 CreateForUser
1903 18362 사용자

생성자

FileOpenPicker()

FileOpenPicker의 새 인스턴스를 만듭니다.

데스크톱 앱에서 UI를 표시하는 방식으로 이 클래스의 인스턴스를 사용하기 전에 개체를 소유자의 창 핸들과 연결해야 합니다. 자세한 정보 및 코드 예제는 CoreWindow에 의존하는 WinRT UI 개체 표시를 참조하세요.

속성

CommitButtonText

파일 열기 선택기 커밋 단추의 레이블 텍스트를 가져오거나 설정합니다.

ContinuationData

앱이 활성화될 때 컨텍스트를 제공하기 위해 앱을 비활성화 하는 PickSingleFileAndContinue 또는 PickMultipleFilesAndContinue 작업 전에 앱에서 채울 값 집합을 가져옵니다. (Windows Phone 8.x 앱)

FileTypeFilter

파일 열기 선택기가 표시하는 파일 형식의 컬렉션을 가져옵니다.

SettingsIdentifier

파일 열기 선택기의 상태와 연결된 설정 식별자를 가져오거나 설정합니다.

SuggestedStartLocation

파일 열기 선택기가 사용자에게 표시할 파일을 찾는 초기 위치를 가져오거나 설정합니다.

User

FileOpenPicker를 만든 사용자에 대한 정보를 가져옵니다. 다중 사용자 애플리케이션에 이 속성을 사용합니다.

ViewMode

파일 열기 선택기가 항목을 표시하는 데 사용하는 보기 모드를 가져오거나 설정합니다.

메서드

CreateForUser(User)

지정된 사용자의 개인 디렉터리로 범위가 지정된 FileOpenPicker 를 만듭니다. 다중 사용자 애플리케이션에 이 메서드를 사용합니다.

PickMultipleFilesAndContinue()

Windows 10 현재 사용되지 않습니다. 대신 PickSingleFolderAsync를 사용합니다. 사용자가 여러 파일을 선택하고, 비활성화하고, 앱을 비활성화하고, 작업이 완료되면 다시 활성화할 수 있도록 파일 선택기를 표시합니다. (Windows Phone 8.x 앱)

PickMultipleFilesAsync()

사용자가 여러 파일을 선택할 수 있도록 파일 선택기를 표시합니다. (UWP 앱)

PickSingleFileAndContinue()

사용자가 하나의 파일을 선택할 수 있도록 파일 선택기를 표시하여 작업이 완료되면 앱을 비활성화하고 다시 활성화할 수 있습니다. (Windows Phone 8.x 앱)

PickSingleFileAsync()

사용자가 하나의 파일을 선택할 수 있도록 파일 선택기를 표시합니다.

PickSingleFileAsync(String)

사용자가 하나의 파일을 선택할 수 있도록 파일 선택기를 표시합니다.

ResumePickSingleFileAsync()

선택 작업이 완료되고 앱이 일시 중단된 후 사용자가 앱에서 벗어나면 사용자가 선택한 파일을 검색하기 위해 선택 작업을 다시 시작합니다.

적용 대상

추가 정보