1 /// <summary> 2 /// 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 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()+"<br/>");18 }19 20 21 }22 23 24 }25 /// <summary>26 /// 查找文件夹下的图片27 /// 2014-08-28 28 /// 涂聚文29 /// </summary>30 /// <param name="searchFolder"></param>31 /// <param name="filters"></param>32 /// <param name="isRecursive"></param>33 /// <returns></returns>34 public static String[] GetFilesFrom(String searchFolder, String[] filters, bool isRecursive)35 {36 List<String> filesFound = new List<String>();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 }
新闻热点
疑难解答