Reputation: 134
I am developing a customer specific application using Windows 10 IoT on a DragonBoard 410c. In this application it is essential to know which drive is the SD card and which one is an additional USB stick. I used to handle this through the drive letters using
KnownFolders.RemovableDevices
since the SD card is supposed to have the drive letter "D". On one board, though, the SD card suddenly had the drive letter "E" and my code failed.
Therefore I started using
var deviceInfos = await DeviceInformation.FindAllAsync( DeviceClass.PortableStorageDevice );
to enumerate the removable drives and then searching the Id
string of every DeviceInformation
object for a specific pattern:
private StorageFolder _sdCard;
private StorageFolder _usbDrive;
foreach( DeviceInformation info in deviceInfos )
{
string id = info.Id.ToUpper();
try
{
if( id.Contains( SDId ) )
{
_sdCard = StorageDevice.FromId( info.Id );
}
else if( id.Contains( USBId ) )
{
_usbDrive = StorageDevice.FromId( info.Id );
}
}
catch( Exception e)
{
Debug.WriteLine( "########## Error " + e );
}
}
Unfortunately, StorageDevice.FromId()
throws NotImplementedException
.
I've enabled the capability for removable storage as well as file type associations in the .appxmanifest
. I do not have any problems accessing files on any removable storage device. Did anyone experience a similar problem and find a solution for it? Does anyone have a different idea of reliably retrieving a StorageFolder
for the SD Card if additional USB sticks might be attached?
Upvotes: 0
Views: 113
Reputation: 134
Just after finishing the question I have found a solution myself, although I am not too happy with it. Using
StorageFolder removableDevices = KnownFolders.RemovableDevices;
IReadOnlyList<StorageFolder> drives = await removableDevices.GetFoldersAsync();
the first element in drives always represents the SD Card, this is also stated here: https://learn.microsoft.com/de-de/windows/uwp/files/access-the-sd-card
But I do not think this is a very reliable solution and I am still looking for something else.
Upvotes: 0