gpt4 book ai didi

c# - Windows Phone 8 SD 卡文件的文件列表

转载 作者:太空宇宙 更新时间:2023-11-03 13:33:23 25 4
gpt4 key购买 nike

我想问一下,有没有人知道从SD卡文件夹中获取所有文件名及其绝对路径并将它们放入列表中的好方法???我正在为 Windows Phone 8 编程。

示例输出:

String[] listOfItems = { "SdcardRoot/Music/a.mp3", 
"SdcardRoot/Music/ACDC/b.mp3",
"SdcardRoot/Music/someartist/somealbum/somefile.someextention" };

感谢您的宝贵时间。

最佳答案

这是一个step by step guide实现你想要的。如果还有什么不清楚的,你也有这个 one from msdn .

你肯定会得到这样的代码:

    private async Task ListSDCardFileContents()
{
List<string> listOfItems = new List<string>();

// List the first /default SD Card whih is on the device. Since we know Windows Phone devices only support one SD card, this should get us the SD card on the phone.
ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
if (sdCard != null)
{
// Get the root folder on the SD card.
ExternalStorageFolder sdrootFolder = sdCard.RootFolder;
if (sdrootFolder != null)
{
// List all the files on the root folder.
var files = await sdrootFolder.GetFilesAsync();
if (files != null)
{
foreach (ExternalStorageFile file in files)
{
listOfItems.Add(file.Path);
}
}
}
else
{
MessageBox.Show("Failed to get root folder on SD card");
}
}
else
{
MessageBox.Show("SD Card not found on device");
}
}

位于 files 循环内的 file 变量的类型为 ExternalStorageFile . Path 属性似乎是您需要的属性:

This path is relative to the root folder of the SD card.

最后,不要忘记在应用程序的 WMAppManifest.xml 中添加 ID_CAP_REMOVABLE_STORAGE 功能注册文件关联:

We need to declare additional capability to register a certain file extension with the application. To ensure that we can read files of a certain type, we need to register file association via extensions in the Application Manifest file. For this, we need to open the WMAppManifest.xml file as code and make the following changes.

关于c# - Windows Phone 8 SD 卡文件的文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19612988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com