CachedFileManager CachedFileManager CachedFileManager CachedFileManager Class

Lets apps manage real-time updates to files.

Syntax

Declaration

public static class CachedFileManagerpublic static class CachedFileManagerPublic Static Class CachedFileManager

Remarks

This class is static and cannot be instantiated. Call the methods directly instead.

Typically, Windows implicitly initiates updates for files that are provided by other apps when those files change. However, you can control when updates are initiated by calling DeferUpdates(Windows.Storage.IStorageFile). If you use this method are deferred until you call CompleteUpdatesAsync(Windows.Storage.IStorageFile) to initiate them.

Examples

The File picker sample shows you how to use a CachedFileManager to defer updates to a file until the app finishes modifying the file.


if (file) {
    // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
    Windows.Storage.CachedFileManager.deferUpdates(file);

    // Write to file
    Windows.Storage.FileIO.appendTextAsync(file, "Swift as a shadow").then(function () {

        // Complete updates. (May require Windows to ask for user input.)
        Windows.Storage.CachedFileManager.completeUpdatesAsync(file).then(function (fileUpdateStatus) {
            switch (fileUpdateStatus) {
                case Windows.Storage.Provider.FileUpdateStatus.complete:
                    // Perform additional tasks like notifying user of status
                    break;

                case Windows.Storage.Provider.FileUpdateStatus.completeAndRenamed:
                    // Perform additional tasks like notifying user of status, or storing the renamed file for future use
                    break;

                default:
                    // Perform additional tasks like notifying user of status
                    break;
            }
        // Handle errors with an error function
        }, function (error) {
            // Handle errors encountered during completeUpdatesAsync
        });
    // Handle errors with an error function
    }, function (error) {
        // Handle errors encountered during appendTextAsync
    });
}
if (file != null)
{
    // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
    CachedFileManager.DeferUpdates(file);

    // Write to file
    await FileIO.AppendTextAsync(file, "Swift as a shadow");
    // Let Windows know that we're finished changing the file so the server app can update the remote version of the file.

    // Complete updates. (May require Windows to ask for user input.)
    FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
    switch (status)
    {
        case FileUpdateStatus.Complete:
            // Perform additional tasks like notifying user of status
            break;

        case FileUpdateStatus.CompleteAndRenamed:
            // Perform additional tasks like notifying user of status, or storing the renamed file for future use
            break;

        default:
            // Perform additional tasks like notifying user of status
            break;
    }
}

In the example, file is a local variable that contains a StorageFile that represents the file to defer updates for.

Methods summary

Initiates updates for the specified file. This method contacts the app that provided the file to perform the updates.

Lets apps defer real-time updates for a specified file.

Methods

  • CompleteUpdatesAsync(Windows.Storage.IStorageFile)
    CompleteUpdatesAsync(Windows.Storage.IStorageFile)
    CompleteUpdatesAsync(Windows.Storage.IStorageFile)
    CompleteUpdatesAsync(Windows.Storage.IStorageFile)

    Initiates updates for the specified file. This method contacts the app that provided the file to perform the updates.

    public static IAsyncOperation<FileUpdateStatus> CompleteUpdatesAsync(Windows.Storage.IStorageFile file)public static IAsyncOperation<FileUpdateStatus> CompleteUpdatesAsync(Windows.Storage.IStorageFile file)Public Static Function CompleteUpdatesAsync(file As Windows.Storage.IStorageFile) As IAsyncOperation( Of FileUpdateStatus )

    Parameters

    Returns

    • When this method completes, it returns a FileUpdateStatus enum value that describes the status of the updates to the file.

    Remarks

    Using this method ensures that the updates to the file are completed which may require Windows to ask for user input. For example, the app that provided the file may be activated to perform updates and that app may display UI through a file picker.

  • DeferUpdates(Windows.Storage.IStorageFile)
    DeferUpdates(Windows.Storage.IStorageFile)
    DeferUpdates(Windows.Storage.IStorageFile)
    DeferUpdates(Windows.Storage.IStorageFile)

    Lets apps defer real-time updates for a specified file.

    public static void DeferUpdates(Windows.Storage.IStorageFile file)public static void DeferUpdates(Windows.Storage.IStorageFile file)Public Static Function DeferUpdates(file As Windows.Storage.IStorageFile) As void

    Parameters

    Remarks

    Typically, Windows implicitly initiates updates for files that are provided by other apps when those files change. However, you can control when updates are initiated by calling DeferUpdates(Windows.Storage.IStorageFile).

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.Storage.dll