{"id":682,"date":"2017-01-12T14:46:52","date_gmt":"2017-01-12T14:46:52","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=394"},"modified":"2022-09-13T15:37:50","modified_gmt":"2022-09-13T14:37:50","slug":"usb-drives-memory-sticks-etc","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/files\/usb-drives-memory-sticks-etc","title":{"rendered":"USB Drives, Memory Sticks, etc"},"content":{"rendered":"<h4>\n\tEnabling Access Of&nbsp;USB Drive Files<\/h4>\n<p>These are located in:<\/p>\n<pre><code>\n\tWindows.Storage.KnownFolders.RemovableDevices\n<\/code><\/pre>\n<p>You will need manifest permissions to access though:<\/p>\n<p style=\"margin-left: 40px\">\n\tOpen Package.appxmanifest &gt; Capabilities &gt; Enable &#8216;Removable Storage&#8217;<\/p>\n<p>\tYou also have to declare what files types you will work with (or you will get Access is denied exception errors when trying to&nbsp;access RemovableDevices):<\/p>\n<p style=\"margin-left: 40px\">\n\tOpen Package.appxmanifest &gt; Declarations &gt; Select &#8216;File Type Associations&#8217; &gt; Add<\/p>\n<p style=\"margin-left: 40px\">\n\tNow with it selected:<\/p>\n<p style=\"margin-left: 80px\">\n\tName: give it a lowercase name, e.g.&#8221;resource_files&#8221;<\/p>\n<p style=\"margin-left: 80px\">\n\tAdd one of more &#8216;Supported file types&#8217; for the files you want to be able to use. &nbsp;E.g. &#8220;.jpg&#8221; (you can leave &#8216;Content type&#8217; blank)<\/p>\n<h4>\n\tList all files and folders on a USB Memory Stick<\/h4>\n<pre><code>\n\tStorageFolder UsbDrive = (await Windows.Storage.KnownFolders.RemovableDevices.GetFoldersAsync()).FirstOrDefault();  \/\/StorageFolder object that maps all removable devices as subfolders.\n\tif (UsbDrive == null)\n\t{\n\t\tSystem.Diagnostics.Debug.WriteLine(\"USB Drive not found\");\n\t}\n\telse\n\t{\n\t\tIReadOnlyList&lt;StorageFolder&gt; FolderList = await UsbDrive.GetFoldersAsync();\n\t\tIReadOnlyList&lt;StorageFile&gt; FileList = await UsbDrive.GetFilesAsync();\n\n\t\tSystem.Diagnostics.Debug.WriteLine(\"LISTING FOLDERS:\");\n\t\tforeach (StorageFolder Folder in FolderList)\n\t\t\tSystem.Diagnostics.Debug.WriteLine(Folder.Name);\n\n\t\tSystem.Diagnostics.Debug.WriteLine(\"LISTING FILES:\");\n\t\tforeach (StorageFile File in FileList)\n\t\t\tSystem.Diagnostics.Debug.WriteLine(File.Name);\n\t}\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enabling Access Of&nbsp;USB Drive Files These are located in: Windows.Storage.KnownFolders.RemovableDevices You will need manifest permissions to access though: Open Package.appxmanifest &gt; Capabilities &gt; Enable &#8216;Removable Storage&#8217; You also have to declare what files types you will work with (or you will get Access is denied exception errors when trying to&nbsp;access RemovableDevices): Open Package.appxmanifest &gt; Declarations [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[],"class_list":["post-682","post","type-post","status-publish","format-standard","hentry","category-files"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=682"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/682\/revisions"}],"predecessor-version":[{"id":1181,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/682\/revisions\/1181"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}