WinRT 有GetFileFromPathAsync()
class 的方法StorageFile
,但是你不能用那个方法打开任何文件。您唯一的选择是使用StorageItemMostRecentlyUsedList
类。这对于获取保存到最近使用的文件列表或未来访问列表的所有文件的令牌很有用。要保存从中访问的令牌FileOpenPicker
,您需要使用StorageApplicationPermissions
类。在这里,我将向您介绍如何保存文件的令牌以及如何检索令牌并访问该文件。
保存令牌
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)
{
// Add to most recently used list with metadata (For example, a string that represents the date)
string mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "20130622");
// Add to future access list without metadata
string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
}
else
{
// The file picker was dismissed with no file selected to save
}
使用令牌检索文件
StorageItemMostRecentlyUsedList MRU = new StorageItemMostRecentlyUsedList();
StorageFile 文件 = 等待 MRU.GetFileAsync(token);
更新
await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(token);