Skip to main content
CachedFileManager class

Lets apps manage real-time updates to files.

Syntax


var cachedFileManager = Windows.Storage.CachedFileManager;

public static class CachedFileManager

Public NotInheritable Class CachedFileManager

public ref class CachedFileManager abstract sealed 

Members

The CachedFileManager class has these types of members:

Methods

The CachedFileManager class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
CompleteUpdatesAsync Initiates updates for the specified file.
DeferUpdates Lets apps defer real-time updates for a specified file.

 

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. If you use this method are deferred until you call CompleteUpdatesAsync 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.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

Attributes

[ MarshalingBehavior(Agile)]
[ Version(0x06020000)]

See also

Object
File picker sample (Windows 10)