I work on an UWP application who manage removable devices. So, I made sure to have this in the manifest.
<Capabilities>
<uap:Capability Name="removableStorage"/>
</Capabilities>
I need to obtain the free and total space of the device. So, I use DriveInfo like this.
DriveInfo z = new DriveInfo(@"E:\");
long x = z.TotalFreeSpace;
This gives the following exception when he tries to obtain the free space and assign it to x :
System.UnauthorizedAccessException : 'Access to the path 'E:\' is denied.'
As you can see, the drive is really a removable drive.
The process I need should occur once the drive as been detected and added. So, this happens in the Added event of a DeviceWatcher
. I see the device is not ready IsReady=false
in the watch window. Maybe I try to access it too soon? The event is "Added", not "Adding" and the UnauthorizedAccessException
is not the one who should occur. I suppose a DeviceNotReadyException
would be more appropriate. So, I conclude the problem is not linked to the fact it is not ready.