格式化篩選後的資料(select new)
1: <script runat="server">
2: new void Page_Load(object sender, EventArgs e)
3: {
4: //取資料夾內的檔案
5: DirectoryInfo dir = new DirectoryInfo(MapPath("~/UploadImages/"));
6: //為抓出的檔名加上路徑
7: var imageList1 = (from x in dir.GetFiles()
8: select new {Name = string.Format("~/UploadImages/{0}", x.Name) }).ToList();
9: lstPhoto.DataSource = imageList1.Select(x=>x.Name);
10: lstPhoto.DataBind();
11: }
12: </script>