Dela via


StorageApplicationPermissions Class

Definition

Provides static properties for you to get your app's most recently used list (MRU) (use StorageApplicationPermissions.MostRecentlyUsedList) and future-access list (use StorageApplicationPermissions.FutureAccessList.

public ref class StorageApplicationPermissions abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class StorageApplicationPermissions final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public static class StorageApplicationPermissions
Public Class StorageApplicationPermissions
Inheritance
Object Platform::Object IInspectable StorageApplicationPermissions
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

This example demonstrates how to add an item to the app's FutureAccessList and MostRecentlyUsedList.

StorageFile file = await savePicker.PickSaveFileAsync();
if (file != null)
{
    // Add to MRU with metadata (For example, a string that represents the date)
    string mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "20120716");

    // Add to FA without metadata
    string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);  
}
else
{
    // The file picker was dismissed with no file selected to save
}
#include <sstream>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.AccessCache.h>
#include <winrt/Windows.Storage.Pickers.h>
using namespace winrt;
using namespace Windows::Storage::Pickers;
using namespace Windows::Storage;
...
winrt::fire_and_forget AddToLists()
{
    FileSavePicker savePicker;
    auto plainTextExtensions{ winrt::single_threaded_vector<winrt::hstring>() };
    plainTextExtensions.Append(L".txt");
    savePicker.FileTypeChoices().Insert(L"Plain Text", plainTextExtensions);
    savePicker.SuggestedFileName(L"New Document");

    StorageFile file{ co_await savePicker.PickSaveFileAsync() };
    if (file)
    {
        // Add to MRU with metadata (For example, a string that represents the date)
        winrt::hstring mruToken { Windows::Storage::AccessCache::StorageApplicationPermissions::MostRecentlyUsedList().Add(file, L"20120716") };

        // Add to FA without metadata
        winrt::hstring faToken { Windows::Storage::AccessCache::StorageApplicationPermissions::FutureAccessList().Add(file) };
    }
    else
    {
        // The file picker was dismissed with no file selected to save
    }
}

It is recommended that you store the tokens returned by StorageApplicationPermissions.MostRecentlyUsedList.Add and StorageApplicationPermissions.FutureAccessList.Add so that you can use them to retrieve the respective list entry for the item that you added. In the example, we store the tokens in mruToken and faToken respectively but we don't do anything else with them.

Additionally, the savePicker variable in the example contains a FileSavePicker object that was created by the sample. To learn more about saving files with file picker, see Save a file with a picker. To learn about accessing files, see Open files and folders with a picker.

Remarks

Access the methods and properties of this class statically.

To see more code examples, see the File picker sample and the File access sample.

To learn about using the FutureAccessList and MostRecentlyUsedList, see Track recently used files and folders.

To learn about what files and locations your app has permission to access, see File access permissions.

Version history

Windows version SDK version Value added
1903 18362 GetFutureAccessListForUser
1903 18362 GetMostRecentlyUsedListForUser

Properties

FutureAccessList

Gets an object that represents a list that an app maintains so that the app can store files and/or locations (like folders) and easily access these items in the future.

MostRecentlyUsedList

Gets an object that represents a list that an app can use to track the files and/or locations (like folders) that the app has accessed most recently.

Methods

GetFutureAccessListForUser(User)

Gets an object that represents a list that an app maintains so that the app can store files and/or locations (like folders) and easily access these items in the future. This method returns an object that is scoped to the specified user. Use this method for multi-user applications.

GetMostRecentlyUsedListForUser(User)

Gets an object that an app can use to track the files and/or locations (like folders) that the app has accessed most recently. This method returns an object that is scoped to the specified user. Use this method for multi-user applications.

Applies to