问题
In WPF, we can access the drives names using GetLogicalDrives() method in System.IO namespace. But for UWP, GetLogicalDrives() method is not in System.IO namespace. So how can I access drives names in windows 10?
回答1:
Nor sure if this answers your question, but:
var removableDevices = KnownFolders.RemovableDevices;
var folders = await removableDevices.GetFoldersAsync();
This will return a collection you can iterate through:
foreach (StorageFolder folder in folders)
{
sb.AppendFormat("DisplayName: {0}", folder.DisplayName);
}
So for a USB stick called "ESD-USB" this will return the name of the drive you see in Explorer along with the drive letter, e.g: "ESD-USB (D:)".
KnownFolders is in the Windows.Storage namespace.
Manifest: Update for question in comments
It's a while since I did any work on this, so not sure if this is all you need to do. Here's the relevant manifest info:
Under Capabilities I have the following ticked: Removable Storage, Pictures Library, Music Library, Videos Library, Internet (Client).
来源:https://stackoverflow.com/questions/37404405/how-to-get-logical-drives-names-in-windows-10