技术员联盟提供win764位系统下载,win10,win7,xp,装机纯净版,64位旗舰版,绿色软件,免费软件下载基地!

当前位置:主页 > 教程 > 电脑常识 >

WP7获取ISolatedStorage指定文件夹下所有子文件夹

来源:技术员联盟┆发布时间:2018-07-11 12:07┆点击:

  进入正题:

  一开始直接使用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", "*"));