【问题标题】:Is there a way to get folders/files cloud provider in WPF .NET 5 like in UWP?有没有办法像在 UWP 中一样在 WPF .NET 5 中获取文件夹/文件云提供程序?
【发布时间】:2021-11-20 08:02:18
【问题描述】:

我正在处理一项任务,我需要找到一种方法来确定文件提供程序(如果有的话)。

我已经尝试过使用 UWP StorageFiles/StorageFolders。

        StorageFile storageFile = await filePicker.PickSingleFileAsync();
        var provider = storageFile.Provider;

代码:在 UWP 中获取 StorageFile 实例。

上面的示例返回一个提供商名称,它将是“计算机”或其他云平台名称。
这在 WPF 中不起作用。我已经尝试过使用 Uno.UI,但似乎有一半的功能没有实现。

提前感谢您! :)

【问题讨论】:

  • 不,目前 .NET 5 中没有这样的东西,但应该有!在相当长的一段时间内,有一个未解决的问题,但看起来可能有一些活动。 github.com/dotnet/runtime/issues/26403

标签: c# wpf uwp storagefile


【解决方案1】:

关键是寻找如何从 WPF 应用程序调用 Windows API。

这里是一个博客链接,一开始我就是这样做的。

https://www.thomasclaudiushuber.com/2019/04/26/calling-windows-10-apis-from-your-wpf-application/

如果您遇到有关 Windows 版本的错误,这可能会有所帮助:

NETSDK1135 SupportedOSPlatformVersion 10.0.19041.0 cannot be higher than TargetPlatformVersion 7.0

编辑:后来我发现只需将 <TargetFramework>net5.0-windows10.0.17763</TargetFramework> 添加到我的项目 .csproj 文件中,我就可以使用 Windows.Storage 命名空间。

现在,当我致电 var file = StorageFile.GetFileFromPathAsync(@"[FilePath]").GetResults(); 时,它会为我提供我正在寻找的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-29
    • 2018-06-10
    • 2021-10-17
    • 2012-01-17
    • 2016-12-20
    • 1970-01-01
    • 2023-01-09
    • 2016-07-09
    相关资源
    最近更新 更多