質問

I'm confused how to get folder list in windows phone 8.1 is there anyone have ever experienced this or have any idea? I want to show all of the folder in storage in a listview Thanks

var storageAssets = await ExternalStorage.GetExternalStorageDevicesAsync();
ExternalStorageDevice item = storageAssets.FirstOrDefault();
ExternalStorageFolder folder = item.RootFolder;
var _folderList = await folder.GetFoldersAsync();
foreach (var _folder in _folderList)
{
     Debug.WriteLine(_folder.Name);
}

I'm trying to show them using debug first before store in listview but the code error says that ExternalStorage dosen't exist

役に立ちましたか?

解決

The MSDN article and will do a better job of explaining than I can, but the summary is:

First you need the following in your manifest file:

    <Capability Name="removableStorage" />

and at least one file type declaration (these are the files that you will be able to access on the SD card:

    <Extension Category="windows.fileTypeAssociation">
      <FileTypeAssociation Name="foo">
        <SupportedFileTypes>
          <FileType ContentType="foo/bar">.bar</FileType>
        </SupportedFileTypes>
      </FileTypeAssociation>
    </Extension>

Then in your code to get the root of the SD card use:

StorageFolder sdCard = (await KnownFolders.RemovableDevices.GetFoldersAsync()).FirstOrDefault();
if (sdCard == null)
{ return; /*no SD card*/}

and to enumerate the folders use:

 IReadOnlyList<StorageFolder> folders = await sdCard.GetFoldersAsync();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top