StorageDevice.FromId | fromId method

Applies to Windows only

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

Syntax

Public Shared Function FromId(
  DeviceId As String 
) As StorageFolder

Parameters

DeviceId

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

The DeviceInformation ID that identifies the removable storage device. This id can be retrieved from Windows.Devices.Enumeration or the DeviceInformationId property of the AutoPlay device event arguments. For more information, see Quickstart: Register an app for an AutoPlay device. In order for FromId to succeed, the app must declare both the removableStorage capability as shown in the App capability declarations and file type associations for the files it wishes to access on the device as shown in How to handle file activation. For more information, see the Removable Storage sample.

Return value

Type: StorageFolder

The storage folder object that represents the removable storage device and provides access to content on the device.

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.

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.

Examples

The following example shows how to get an interface ID using GetDeviceSelector and the Windows.Devices.Enumeration API, and how to pass it to FromId 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 a StorageFolder 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 in C# and C++.

No code example is currently available or this language may not be supported.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

Windows.Devices.Portable
Windows::Devices::Portable [C++]

Metadata

Windows.winmd

Capabilities

removableStorage

See also

StorageDevice
DeviceInformation
DeviceInformation.Id
Enumerating Common Devices

 

 

Show:
© 2014 Microsoft. All rights reserved.