从Windows Phone 8.1中的FolderPicker获取文件夹

时间:2015-05-06 10:12:30

标签: windows-phone-8.1

我已尝试使用此代码在Windows Phone上获取文件夹。

    FolderPicker folderPicker = new FolderPicker();
    folderPicker.SuggestedStartLocation = PickerLocationId.Downloads;
    StorageFolder folder = await folderPicker.PickSingleFolderAsync();

    if (folder != null)
    {
        string Token = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(folder, folder.Name);

    }

但Windows Phone 8.1不支持PickSingleFolderAsync,而PickFolderAndContinue是无效功能。

如何将文件夹添加到StorageApplicationPermissions.MostRecentlyUsedList

1 个答案:

答案 0 :(得分:1)

根据MSDN File picker sample,您会注意到可以在PickFolderAndContinue回调方法(ContinueFolderPicker)上检索该文件夹。

以下是示例中的代码段:

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."; 
        } 
    } 

希望这有帮助吗?