StorageDevice StorageDevice StorageDevice StorageDevice Class

Provides methods for accessing the storage functionality of a portable device that supports WPD. Removable storage devices include:

  • USB mass storage flash drives and cameras
  • Media Transfer Protocol (MTP) music players, phones, and cameras
  • Picture Transfer Protocol (PTP) cameras

Syntax

Declaration

public static class StorageDevicepublic static class StorageDevicePublic Static Class StorageDevice

Remarks

To access the device services, you must declare the device service in the capabilities section of the app manifest file. For a list of the GUIDs representing the device services, see Windows.Devices.Portable.

Examples

The following example shows how to get an interface ID using GetDeviceSelector() and the Windows.Devices.Enumeration API. It also shows how to pass it to FromId(System.String) to get a StorageFolder for a removable storage device.

    Enum = Windows.Devices.Enumeration;

    // Enumerate removable storage devices.
    // The success callback selects the removable storage to use.
    function pickStorageToGetImageFrom() {
        Enum.DeviceInformation.findAllAsync(
        Windows.Devices.Portable.StorageDevice.getDeviceSelector(),
        null).then(
            successCallback,
            errorCallback);
    }

    // Handler that's called when removable storages are found.
    // storageDevices: A collection of type
    // Windows.Devices.Enumeration.DeviceInformationCollection.
    // This example just takes the first storage found in the list.
    function successCallback(storageDevices) {
        var removableStorage = null;
        if (storageDevices.length) {
            try {
                // Get the StorageFoler from the id for the first removable storage device
                removableStorage = Windows.Devices.Portable.StorageDevice.fromId(
                storageDevices.getAt(0).id);
                // document.getElementById("output").innerHTML = storageDevices.getAt(0).name; 
            } catch (e) {
                document.getElementById("output").innerHTML =
                "Error: " + e.message;
            }
            if (removableStorage != null) {
                getImageFiles(removableStorage);
            }
        } else {
            document.getElementById("output").innerHTML =
                "No removable storage devices were found.";
        }
    }

The following examples show the syntax of a call to FromId(System.String) in C# and C++.

var folder = StorageDevice.FromId(deviceInformationId);
StorageFolder^ folder = StorageDevice::FromId(deviceInformationId);

Methods summary

Gets a StorageFolder object from a DeviceInformation Id for a removable storage device.

An Advanced Query Syntax (AQS) string for identifying removable storage devices. This string is passed to the FindAllAsync(System.String) or CreateWatcher() method.

Methods

  • FromId(System.String)
    FromId(System.String)
    FromId(System.String)
    FromId(System.String)

    Gets a StorageFolder object from a DeviceInformation Id for a removable storage device.

    public static StorageFolder FromId(System.String deviceId)public static StorageFolder FromId(System.String deviceId)Public Static Function FromId(deviceId As System.String) As StorageFolder

    Parameters

    Returns

    Remarks

    Pass the selector string from GetDeviceSelector() to the Windows.Devices.Enumeration API to get a collection of DeviceInformation objects representing storage devices. Select the DeviceInformation object for the storage you want to access, and use its Id property as the deviceInformationId parameter to FromId(System.String).

  • GetDeviceSelector()
    GetDeviceSelector()
    GetDeviceSelector()
    GetDeviceSelector()

    An Advanced Query Syntax (AQS) string for identifying removable storage devices. This string is passed to the FindAllAsync(System.String) or CreateWatcher() method.

    public static string GetDeviceSelector()public static string GetDeviceSelector()Public Static Function GetDeviceSelector() As string

    Returns

    • string
      string
      string
      string

      An AQS string for identifying storage devices.

Device family

Windows Desktop Extension SDK (introduced v10.0.10240.0)

API contract

Windows.Devices.Portable.PortableDeviceContract (introduced v1)

Capabilities

removableStorage

Attributes

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

Details

Assembly

Windows.Devices.Portable.dll