0

The question is very simple, I want to list all drives on my pc.

We all know how to list drives with:

DriveInfo.GetDrives();

Directory.GetLogicalDrives();

But what if I need to list my CELLPHONE as a drive, I can see it on explorer, so why is not listed on the result of this 2 methods?

I tested this methods with 2 kind of cellphones.

  • Android: LG G4 Stylus LTE (internal and SDcard, so here you have 2 drives)
  • Windows phone: Lumia 1020 (no SDcard)

Still, no result.

Help please!

Yogurtu
  • 2,656
  • 3
  • 23
  • 23
  • DriveInfo doesn't provide a way to listen for USB Key Insertions. Take a look at this http://stackoverflow.com/questions/620144/detecting-usb-drive-insertion-and-removal-using-windows-service-and-c-sharp – Mainak Mar 19 '16 at 05:30
  • Thanks for your comment, but it only says how to detect when a device is connected, I need to browse the device, and get files inside. – Yogurtu Mar 21 '16 at 00:52

1 Answers1

0

Those cellphones aren’t drives, they’re WPD devices.

If you only want to list those, Windows includes COM API for that.

Here’s a C++ sample.

It’s possible to do the same without C++, in C# using COM interop. It takes some time to setup (you’ll have to reference two COM type libs, PortableDeviceApiLib and PortableDeviceTypesLib, and workaround some issues with COM type library importer) and also to learn the API, but I once did that for some client, the solution worked OK.


If however you not only need MTP devices, but whatever stuff Windows Explorer shows under “This PC” (can be anything, some third-party applications or drivers register their own shell extensions adding stuff to “This PC”), then you’ll need completely different API, but again it’s COM API. Windows provides IShellFolder interface to enumerate stuff.

Here’s some article about something similar in C#.

Soonts
  • 20,079
  • 9
  • 57
  • 130