C# 获取wp8中文件夹中的文件数
我试图获取文件夹中的文件数,但它给我以下异常C# 获取wp8中文件夹中的文件数,c#,windows-phone-8,C#,Windows Phone 8,我试图获取文件夹中的文件数,但它给我以下异常 {System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Data\Programs\{6AF473D1-D227-423A-B6A6-EA76F880B1F8}\Install\Mp3 Files\0\113' 我正在使用下面的方法检索文件 public static bool versesExists(byte suraNumber, byte re
{System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Data\Programs\{6AF473D1-D227-423A-B6A6-EA76F880B1F8}\Install\Mp3 Files\0\113'
我正在使用下面的方法检索文件
public static bool versesExists(byte suraNumber, byte reciterID)
{
string folderPath = string.Format("{0}{1}{2}", @"Mp3 Files\", reciterID, @"\" + suraNumber + @"\");
int totalSuraAyas = 0;
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storage.DirectoryExists(folderPath))
{
try
{
DirectoryInfo dir = new System.IO.DirectoryInfo(folderPath);
FileInfo[] files = dir.GetFiles("*.mp3");
if (files.Length == totalSuraAyas)
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
}
return false;
}
如果您看到我正在检查目录是否存在,然后查找文件,但它在“GetFiles(*.mp3)”中为我提供了异常,我不知道如何使用它?最可能的原因是,您正在尝试访问独立存储
使用诸如“GetFileNames()”或OpenFile()之类的隔离存储方法访问隔离存储文件。文件夹路径中不应有空间 Mp3文件应该是Mp3文件
string folderPath = string.Format("{0}{1}{2}", @"Mp3Files\", reciterID, @"\" + suraNumber + @"\");
我认为您必须使用IsolatedStorageFile实例上的方法来访问任何文件系统内容。请参阅:非常感谢,终于在字符串末尾添加了[]fileNames=isoFile.GetFileNames(“Archive\*”);我会接受你的回答,我知道马克确实为我的问题提供了足够的信息。