1 ///2 /// 3 /// 4 /// 5 /// 6 protected void Page_Load(object sender, EventArgs e) 7 { 8 if (!IsPostBack) 9 {10 path = Server.MapPath("images/");11 12 String searchFolder = path;13 String[] filters = new String[] { "jpg", "jpeg", "png", "gif", "tiff", "bmp" };14 String[] files = GetFilesFrom(searchFolder, filters, false);15 for (int i = 0; i < files.Length; i++)16 {17 Response.Write(files[i].ToString()+"");18 }19 20 21 }22 23 24 }25 ///26 /// 查找文件夹下的图片27 /// 2014-08-28 28 /// 涂聚文29 /// 30 /// 31 /// 32 /// 33 ///34 public static String[] GetFilesFrom(String searchFolder, String[] filters, bool isRecursive)35 {36 List filesFound = new List ();37 SearchOption searchOption = isRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;38 foreach (string filter in filters)39 {40 filesFound.AddRange(Directory.GetFiles(searchFolder, String.Format("*.{0}", filter), searchOption));41 }42 return filesFound.ToArray();43 }