c# - 使用 C# Windows 10 iot core 将文件复制到 USB
问题描述
我正在尝试复制在 Windows 10 iot 核心的本地文件夹中创建的 .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 = 等待 UsbDevice.FromIdAsync(myDevices[0].Id);
“myDevices[0].Id”引发了“System.ArgumentOutOfRangeException”类型的异常
我试过检查这是否为空且不为空。
这样做的目的是基本上将一些文本文件从本地文件夹复制到 USB 驱动器。
解决方案
使用 UsbDevice.GetDeviceSelector 找不到 USB 存储,Windows.Devices.Usb命名空间中的方法用于有效的 WinUSB 设备,其兼容 id 为USB\MS_COMP_WINUSB,但 USB 存储不会包含兼容 id。事实上, KnownFolders.RemovableDevices 足以访问设备。
推荐阅读
- validation - Tkinter checkbutton bind 不取更新值
- python - 从 .csv 文件传输到文本文件的数据中删除 'b 和 \n
- html - 如何为 bootstrap 3 nav-tabs 添加填充
- xamarin.forms - 将大图片上传到 FTP 会冻结应用程序
- java - Java:同一类的另一个实例的访问方法
- fullcalendar - fullcalendar 是否支持导出到 Google 日历?
- angular - 如何将子组件路由到另一个子组件
- excel - 多行文本框到 Excel 错误粘贴到 Outlook HTML
- swift - 通过字符串双精度对结构数组进行快速排序
- nginx - Nginx 反向代理返回“504 Timeout while reading response from server”