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);
	}

 

 

UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.