Search code examples
c#usbuwpdetection

UWP usb detection


I would like to detect a USB drive in my app (on launch) but I can't find a simple way to do that!

In WinForms I used DriveInfo but it doesn't exist in UWP.

I found this: How to get notifications if devices are added, removed, or changed (XAML) but it's not very simple at all! And it finds everything but my USB drive! (or it doesn't show it with the good name).

Can you help me please? Thanks


Solution

  • Check this sample on DeviceEnumerationAndPairing

    If you want this to be done when your app is open, then see Scenario 2

    If you want this to be done when your app is not open ( background), then see Scenario 3.

    In the sample, When i connected my USB, I was able to see the Device Interface ID and also the Name. This should help you get started.

    Edit 2: So based on your requirement, See the documentation for KnownFolders.Removable Devices

    This will give you all files and folders from a new added removable device (on phone with OTG or SD Card )