您当前的位置: 首页 > 电脑基础知识 > 电脑基本常识 浏览
WP7获取ISolatedStorage指定文件夹下所有子文件夹
发布时间:2016-02-01    点击率:次    来源:www.sytcke.com    作者:电脑技术学习网

  进入正题:

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

  string[] folderlist; IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

  if(iso.DirectoryExists("folder"))

  {

  folderlist=iso.GetDirectoryNames("folder");

  }

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

  public string[] GetDirectoryNames();

  //

  // 摘要:

  // 枚举独立存储范围中与给定模式匹配的目录。

  //

  // 参数:

  // searchPattern:

  // 搜索模式。单字符 ("?") 和多字符 ("*") 通配符都受支持。

  //

  // 返回结果:

  // 独立存储范围中与 searchPattern 匹配的目录的相对路径 System.Array。零长度数组指定没有任何匹配的目录。

  GetDirectoryNames的搜索模式。单字符 ("?") 和多字符 ("*") 通配符都受支持。于是问题也就明白了。正确代码:

  string[] folderlist;

  IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

  if(iso.DirectoryExists("folder"))

  {

  folderlist=iso.GetDirectoryNames(System.IO.Path.Combine("folder", "*"));

  }

来源 电脑技术网 www.sytcke.com
发表留言
发表留言请先登录!
免责声明:本站发布的信息和评论纯属网民个人行为,并不代表本站立场,如发现有违法信息或侵权行为,请直接与本站管理员联系,我们将在收到您的信息后24小时内作出处理!