StorageDevice
StorageDevice
StorageDevice
StorageDevice
Class
Definition
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
public : static class StorageDevicepublic static class StorageDevicePublic Static Class StorageDevice// You can use this class in JavaScript.
- Attributes
| Device family |
Windows Desktop Extension SDK (introduced v10.0.10240.0)
|
| API contract |
Windows.Devices.Portable.PortableDeviceContract (introduced v1)
|
| Capabilities |
removableStorage
|
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 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 in C# and C++.
var folder = StorageDevice.FromId(deviceInformationId);
StorageFolder^ folder = StorageDevice::FromId(deviceInformationId);
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.
Methods
FromId(String) FromId(String) FromId(String) FromId(String)
Gets a StorageFolder object from a DeviceInformation Id for a removable storage device.
public : static StorageFolder FromId(PlatForm::String deviceId)public static StorageFolder FromId(String deviceId)Public Static Function FromId(deviceId As String) As StorageFolder// You can use this method in JavaScript.
- deviceId
- PlatForm::String String String String
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.
The storage folder object that represents the removable storage device and provides access to content on the device.
| Device family |
Windows Desktop Extension SDK (introduced v10.0.10240.0)
|
| API contract |
Windows.Devices.Portable.PortableDeviceContract (introduced v1)
|
| Capabilities |
removableStorage
|
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.
- See Also
GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()
An Advanced Query Syntax (AQS) string for identifying removable storage devices. This string is passed to the FindAllAsync or CreateWatcher method.
public : static PlatForm::String GetDeviceSelector()public static string GetDeviceSelector()Public Static Function GetDeviceSelector() As string// You can use this method in JavaScript.
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
|
- See Also