Enabling Access Of USB Drive Files

These are located in:


	Windows.Storage.KnownFolders.RemovableDevices

You will need manifest permissions to access though:

Open Package.appxmanifest > Capabilities > Enable ‘Removable Storage’

You also have to declare what files types you will work with (or you will get Access is denied exception errors when trying to access RemovableDevices):

Open Package.appxmanifest > Declarations > Select ‘File Type Associations’ > Add

Now with it selected:

Name: give it a lowercase name, e.g.”resource_files”

Add one of more ‘Supported file types’ for the files you want to be able to use.  E.g. “.jpg” (you can leave ‘Content type’ blank)

List all files and folders on a USB Memory Stick


	StorageFolder UsbDrive = (await Windows.Storage.KnownFolders.RemovableDevices.GetFoldersAsync()).FirstOrDefault();  //StorageFolder object that maps all removable devices as subfolders.
	if (UsbDrive == null)
	{
		System.Diagnostics.Debug.WriteLine("USB Drive not found");
	}
	else
	{
		IReadOnlyList<StorageFolder> FolderList = await UsbDrive.GetFoldersAsync();
		IReadOnlyList<StorageFile> FileList = await UsbDrive.GetFilesAsync();

		System.Diagnostics.Debug.WriteLine("LISTING FOLDERS:");
		foreach (StorageFolder Folder in FolderList)
			System.Diagnostics.Debug.WriteLine(Folder.Name);

		System.Diagnostics.Debug.WriteLine("LISTING FILES:");
		foreach (StorageFile File in FileList)
			System.Diagnostics.Debug.WriteLine(File.Name);
	}

 

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *