我正在使用 C# 开发 Windows 8 应用程序。
在这里,我使用 FilePicker 从我想要的位置选择文件,
我知道我从本地驱动器中选择的文件的路径。
我想使用该文件作为存储文件。
StorageFile Newfile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(Path); // Path is file path
StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(Path);
但这仅适用于我的项目所在的位置,另一个项目适用于从图片库加载文件。
任何人都可以给我正确的方法吗?
Thanks.
WinRT 有GetFileFromPathAsync()
类的方法StorageFile
,但您无法使用该方法打开任何文件。你唯一的选择就是使用StorageItemMostRecentlyUsedList
班级。这对于获取保存到其中的所有文件的令牌很有用最近使用的文件列表 http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.storageapplicationpermissions.mostrecentlyusedlist or 未来访问列表 http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.storageapplicationpermissions.futureaccesslist。保存访问者的令牌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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)