((UWP Application的任何文件夹)侦听器

问题描述 投票:0回答:1

我需要访问本地文件系统上某处的随机文件夹。

UWP通常无法访问它们,并且设置“ broadFileSystemAccess”的方法不会奏效。

在UWP App中访问这些文件夹和文件的好方法是什么?我曾考虑编写一个小型WPF应用程序,将这些文件从随机文件夹复制到我的UWP应用程序可以访问的文件夹中。

我感谢任何建议。

亲切的问候

c# xamarin uwp directory access
1个回答
0
投票

您可以使用FileOpenPicker访问本地位置,例如,使用FileOpenPicker访问PictureLibrary。有关FileOpenPicke的更多信息,可以参考以下文档:Click

var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");

Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
    // Application now has read/write access to the picked file
    this.textBlock.Text = "Picked photo: " + file.Name;
}
else
{
    this.textBlock.Text = "Operation cancelled.";
}

我不知道您如何使用broadFileSystemAccess功能并导致这种意外行为。通常,broadFileSystemAccess功能使您能够使用StorageFolder(Storagefile)API访问文件夹,例如:

StorageFile file = await StorageFile.GetFileFromPathAsync(@"D:\test.txt");

有关访问其他位置的更多信息,您可以参考本文档:Click

© www.soinside.com 2019 - 2024. All rights reserved.