获取文件夹中的图片

前台:

<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();

posted @ 2011-12-05 16:49  放哨De老鼠  阅读(708)  评论(3编辑  收藏  举报