3

I'm trying to make an app that detects whether my Nokia Lumia 520 is plugged into my laptop. I've tried looking at:

    foreach (DriveInfo drive in DriveInfo.GetDrives())

Windows detects the "C" and "D" drives, but not windows phone.

How come windows does not assign a drive letter to this device? When I go to "My computer", what I see is "Computer\Windows Phone".

I've tried:

    if(Directory.Exists(@"Computer\Windows Phone"))
    {
        MessageBox.Show("Found");
    }

This it is not signalling to me that there is such a directory.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
hedgesketch
  • 197
  • 1
  • 2
  • 10
  • You can't access the phone using file system APIs, because it's not mounted on the file system. You need to use the [Media Transport Protocol](http://en.wikipedia.org/wiki/Media_Transfer_Protocol) to do it. On Windows 8, WinRT provides a simple API to access MTP devices, but I'm afraid it's going to be significantly harder on Windows 7... – Thomas Levesque Nov 08 '14 at 20:32
  • @Sybren, it has nothing to do with what the OP wants; it's a library to help websites detect mobile browsers. – Thomas Levesque Nov 08 '14 at 20:34

1 Answers1

0

You have to use the Windows Portable Devices APIs. They provide a sample application that enumerates portable devices, but it is in C++. However you can still right a C# application that uses those APIs since they are COM interfaces. Check this blog-post that does exactly that (The blog has many other useful posts on this topic).

If you only want to check if the device is connected however, then you could do this.

Community
  • 1
  • 1
Michalis
  • 543
  • 1
  • 4
  • 10