語言

PickFileResult 類別

定義

代表檔案選擇操作的結果。 這是一個輕量級類別,包含一個字 串 屬性,代表檔案路徑。

public ref class PickFileResult sealed
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Windows.Storage.Pickers.StoragePickersContract, 65544)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class PickFileResult final
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Windows.Storage.Pickers.StoragePickersContract), 65544)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class PickFileResult
Public NotInheritable Class PickFileResult
繼承
Object Platform::Object IInspectable PickFileResult
屬性

範例

以下範例示範如何使用 PickFileResult 類別取得所選檔案的檔案路徑:

using Microsoft.Windows.Storage.Pickers;

var picker = new FileOpenPicker();
var result = await picker.PickSingleFileAsync();
if (result != null)
{
    // Perform this conversion if you have business logic that uses StorageFile
    var storageFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(result.Path)
    // Continue your business logic with storageFile
}
else
{
    // Add error handling logic here
}
#include <winrt/Microsoft.Windows.Storage.Pickers.h>
using namespace winrt::Microsoft::Windows::Storage::Pickers;

FileOpenPicker picker;
auto& result{ co_await openPicker.PickSingleFileAsync() };
if (result)
{
    // Perform this conversion if you have business logic that uses StorageFile
    auto& storageFile{ co_await winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(result.Path) }
    // Continue your business logic with storageFile
}
else
{
    // Add error handling logic here
}

備註

PickFileResult 物件可以轉換成 Windows。透過 GetFileFromPathAsync 使用檔案路徑來取得 Storage.StorageFile 物件。

屬性

名稱 Description
Path

一個包含使用者在檔案選擇對話框中選擇檔案路徑的 字串 。

適用於

另請參閱