asp.net 获取文件夹中的图片的代码 |
本文标签:文件夹,图片 前台: 复制代码 代码如下: <asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="5" CellSpacing="25"> <ItemTemplate> <img src="<%# Eval("FullName") %>" width="50" height="50" border="0" > </ItemTemplate> </asp:DataList> 后台代码: 复制代码 代码如下: string path = Server.MapPath("img");//获取img文件夹的路径 Response.Write(path); DirectoryInfo di = new DirectoryInfo(path); //DataList1.DataSource = di.GetFiles("*.jpg");只获取jpg图片 DataList1.DataSource = di.GetFiles();//获取文件夹下所有的文件 DataList1.DataBind(); |