user3639685
user3639685

Reputation: 25

Get list of folders and files in SD card

I've already accessed SD card, but I'm confused how to get list of folders and files in the SD card root and it's child, can anyone help me?

StorageFolder sdCard = (await KnownFolders.RemovableDevices.GetFoldersAsync()).FirstOrDefault();

if (sdCard == null)
{                          
   t1.Text = "Not Found";
}
else
{
  //t1.Text = "Found";
  //here i want to get list folder and files
}

Upvotes: 2

Views: 2115

Answers (1)

Romasz
Romasz

Reputation: 29792

Here at MSDN you have nice examples. Basicly you get a StorageFolder, so you can get list of your items by using GetItemsAsync() (files and folders) or directly GetFilesAsync() and GetFoldersAsync(). Simple example:

List of folders:

IReadOnlyList<StorageFolder> folderList = await sdCard.GetFoldersAsync();

List of files:

IReadOnlyList<StorageFile> fileList = await sdCard.GetFilesAsync();

Note also that to use SD card you have to add Removable Storage capability in your package.appxmanifest file.

And remember that your App can access only files for which you have declared File Type Association (again package.appxmanifet file, Declarations tab), more at MSDN:

What you can access

Your app can only read and write files of file types that the app has registered to handle in the app manifest file.

Your app can also create and manage folders.

Without this, you won't be able to see the files.

Upvotes: 2

Related Questions