Quickstart: Determining availability of Microsoft OneDrive files
Language: HTML | XAML

Quickstart: Determining availability of Microsoft OneDrive files (HTML)

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Determine if a Microsoft OneDrive file is available using the StorageFile.isAvailable property.

Prerequisites

Many of the methods used to interact with folders and files are asynchronous. You can learn how to write asynchronous apps in Asynchronous programming in JavaScript.

Using the StorageFile.isAvailable property

In Windows 8.1, users are able to mark OneDrive files as either available-offline (default) or online-only. This capability enables users to move large files (such as pictures and videos) to their OneDrive, mark them as online-only, and save disk space (as a file containing only metadata about the remote file is kept locally).

A new property, StorageFile.isAvailable, is used to determine if a file is currently available. The following table shows the value of the StorageFile.isAvailable property in various scenarios.

Type of fileOnlineMetered networkOffline
Local fileTrueTrueTrue
OneDrive file marked as available-offlineTrueTrueTrue
OneDrive file marked as online-onlyTrueBased on user settingsFalse
Network fileTrueBased on user settingsFalse

 

The following steps illustrate how to determine if a file is currently available.

  1. Define the appropriate library access capabilities. Depending on the library that is being enumerated, you'll need to define the capability to access that library. To learn more about this and defining other file-level capabilities for Microsoft Visual Studio projects, see File access and permissions for Windows Store apps.
  2. Acquire a StorageFolder object representing the folder whose files will be enumerated. This is done by referencing one of the Windows.Storage.KnownFolders static properties, such as Windows.Storage.KnownFolders.picturesLibrary.
  3. Call the StorageFolder.getFilesAsync method to retrieve all files in the associated folder.
  4. Iterate over the returned file collection, referencing the isAvailable property for each StorageFile object.

The following method enumerates the Pictures Library and displays the name, provider name, and availability for each file.


function OnDisplayAvailabilityClick(mouseEvent) {
    var output = document.getElementById("Output");

    var library = Windows.Storage.KnownFolders.picturesLibrary;
    var outString = "";
    library.getFilesAsync().then(function (files) {
        files.forEach(function (file) {
            outString += file.name + " (on " + file.provider.displayName + ") is " + (file.isAvailable ? "available" : "not available") + "\n";
        });
        output.innerText = outString;
    });
}

Summary

In this quickstart, you learned how to programmatically determine if a OneDrive file is available.

 

 

Show:
© 2016 Microsoft