Windows Phone 7获取ISolatedStorage指定文件夹下所有子文件夹

前不久做了一个电子书阅读器,需要从服务器上下载epub格式的电子书,epub实际上就是zip,关于zip解压请看

http://www.cnblogs.com/youhui/archive/2012/04/05/2433904.html

进入正题:

一开始直接使用GetDirectoryNames("folder\\")

            IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
            if(iso.DirectoryExists("folder"))
            {
                  string[] folderlist=iso.GetDirectoryNames("folder\\");
            }

 

运行后发现这样写并不能获取到folder的子文件夹,经过一番折磨后发现问题出在GetDirectoryNames的参数,看看GetDirectoryNames的定义:

public string[] GetDirectoryNames();
//
// 摘要:
// 枚举独立存储范围中与给定模式匹配的目录。
//
// 参数:
// searchPattern:
// 搜索模式。单字符 ("?") 和多字符 ("*") 通配符都受支持。
//
// 返回结果:
// 独立存储范围中与 searchPattern 匹配的目录的相对路径 System.Array。零长度数组指定没有任何匹配的目录。
GetDirectoryNames的搜索模式。单字符 ("?") 和多字符 ("*") 通配符都受支持。于是问题也就明白了。
正确代码:
            IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
            if(iso.DirectoryExists("folder"))
            {
                  string[] folderlist=iso.GetDirectoryNames(System.IO.Path.Combine("folder", "*")); 
            }

 

 

本人的第一篇文章,望多多指教

 
posted on 2012-11-21 21:13  钊哥  阅读(415)  评论(4)    收藏  举报