语言

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 对象。

属性

名称 说明
Path

一个 字符串 ,其中包含用户在文件选取器对话框中选择的文件的路径。

适用于

另请参阅