你好,
你的需求在官方的sample中有部分实现:https://code.msdn.microsoft.com/windowsapps/File-picker-sample-9f294cba
在其中第三个案例中,使用到了ContinuationManager 帮助类,它可以记住在进行下一步时,用户的操作和完成的任务。
然后使用 FolderPickerContinuationEventArgs.Folder 属性就可以记录文件夹:
http://msdn.microsoft.com/en-us/library/windows.applicationmodel.activation.folderpickercontinuationeventargs.folder.aspx
private void PickFolderButton_Click(object sender, RoutedEventArgs e)
{
// Clear previous returned folder name, if it exists, between iterations of this scenario
OutputTextBlock.Text = "";
FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
folderPicker.FileTypeFilter.Add(".docx");
folderPicker.FileTypeFilter.Add(".xlsx");
folderPicker.FileTypeFilter.Add(".pptx");
folderPicker.PickFolderAndContinue();
}
/// <summary>
/// Handle the returned folder from folder picker
/// This method is triggered by ContinuationManager based on ActivationKind
/// </summary>
/// <param name="args">Folder picker continuation activation argment. It cantains the folder user selected with folder picker </param>
public void ContinueFolderPicker(FolderPickerContinuationEventArgs args)
{
StorageFolder folder = args.Folder;
if (folder != null)
{
// Application now has read/write access to all contents in the picked folder (including other sub-folder contents)
// 应用现在对于所选文件夹内的文件均获得读写权限(包括子文件夹)
StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
OutputTextBlock.Text = "Picked folder: " + folder.Name;
}
else
{
OutputTextBlock.Text = "Operation cancelled.";
}
}
当应用加载的时候,只需要获得FutureAccessList中的数据,即可实现你要的效果,可参考以下文档:
#How to track recently used files and folders
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh972344(v=win.10).aspx
String mruFirstToken = StorageApplicationPermissions.MostRecentlyUsedList.Entries.First.Token;
StorageFile retrievedFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruFirstToken);
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.