![](/img/trans.png)
[英]Using DeviceID from Windows.Devices.Enumeration to find the Drive Letter of a Removable Drive (USB) in C# Windows 10 IoT Core?
[英]Copy files to USB using C# Windows 10 iot core
我正在嘗試復制在 Windows 10 物聯網核心的本地文件夾中創建的 .csv 文件。 我嘗試了幾種方法,但沒有運氣。 我的最新代碼如下:
string aqs = UsbDevice.GetDeviceSelector(0x045E, 0x0611);
var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(aqs);
UsbDevice usbDevice;
try
{
if(myDevices == null)
{
return;
}
usbDevice = await UsbDevice.FromIdAsync(myDevices[0].Id);
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFolder sourcef = await localFolder.CreateFolderAsync("My Data", CreationCollisionOption.OpenIfExists);
IReadOnlyList<StorageFile> filel = await sourcef.GetFilesAsync();
StorageFolder removableDevices = KnownFolders.RemovableDevices;
//var externalDrives = await removableDevices.GetFoldersAsync();
//var drive0 = externalDrives[0];
//var destFolder = await removableDevices.CreateFolderAsync("My Data", CreationCollisionOption.GenerateUniqueName);
foreach (StorageFile file in filel)
{
await file.CopyAsync(removableDevices);
}
}
在上面我得到一個例外:
usbDevice = await UsbDevice.FromIdAsync(myDevices[0].Id);
“myDevices[0].Id”拋出了“System.ArgumentOutOfRangeException”類型的異常
我試過檢查這是否為空並且它不為空。
這樣做的目的是基本上將幾個文本文件從本地文件夾復制到 USB 驅動器。
使用 UsbDevice.GetDeviceSelector 無法找到 USB 存儲, Windows.Devices.Usb命名空間中的方法用於具有兼容 id USB\\MS_COMP_WINUSB 的有效 WinUSB 設備,但 USB 存儲不會包含兼容 id。事實上,KnownFolders.RemovableDevices 足以訪問設備。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.