【问题标题】:Drive Letter of Devices on UWP Universal AplicationUWP 通用应用程序上的设备驱动器号
【发布时间】:2018-04-21 13:12:39
【问题描述】:
var myDevices= await Windows.Devices.
    Enumeration.DeviceInformation.
    FindAllAsync(Windows.Devices.Enumeration.DeviceClass.PortableStorageDevice);

foreach(var x in myDevices)
{
    string s = string.Format("Kind:{0} Name:{1} Id:{2})",
        x.Kind.tostring(), x.Name, x.Id);
    listbox1.items.add(s);
}

这是我的示例代码。是否可以检测到我可以访问 myDevices 对象项的驱动器的属性? (类似于 D:\ 或 E:\ 等)。甚至我可以在 Windows IOT 仪表板中看到驱动器号 (不知道是否有意义,但平台是 rasperry pi3 上的物联网)

【问题讨论】:

  • @VMAtm 指出您可以使用RemovableDevices 的子文件夹的路径属性获取此类驱动器名称。

标签: c# uwp win-universal-app windows-10-iot-core


【解决方案1】:

找到this有关Windows 8 的文章,也许它仍然适用于您的情况?基本上它说您可以通过两种方式将设备作为文件夹获取:

  • KnownFolders.RemovableDevices 与每个设备的StorageFolder 对象,可用于确定路径
  • 通过Windows.Devices.Portable.StorageDevice.FromId(device.Id); 为您在myDevices 中找到的每个设备提供StorageDevice 和DeviceInformation

MSDN 上的Access the SD card 文章还提到了StorageFolder 类作为获取路径信息的一种方式。

旁注:您可以使用字符串插值来简化字符串构造:

string s = $"Kind:{x.Kind} Name:{x.Name} Id:{x.Id})";

【讨论】:

    猜你喜欢
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多