时间:2021-01-07 11:24:38 | 栏目:.NET代码 | 点击:次
本文实例讲述了C#显示文件夹下所有图片文件的方法。分享给大家供大家参考。具体实现方法如下:
<%@ Page Language="C#" EnableViewState="false" %> <%@ Import Namespace="System.IO" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { FileInfo[] fs1 = (new DirectoryInfo(Server.MapPath("~/A"))).GetFiles(); FileInfo[] fs2 = (new DirectoryInfo(Server.MapPath("~/B"))).GetFiles(); FileInfo[] fs3 = (new DirectoryInfo(Server.MapPath("~/C"))).GetFiles(); FileInfo[] fs4 = (new DirectoryInfo(Server.MapPath("~/D"))).GetFiles(); FileInfo[] fs5 = (new DirectoryInfo(Server.MapPath("~/E"))).GetFiles(); var fs = fs1.Concat(fs2).Concat(fs3).Concat(fs4).Concat(fs5); Repeater1.DataSource = fs; Repeater1.DataBind(); } string GetUrl(object img) { FileInfo f = img as FileInfo; return Page.ResolveUrl("~")+f.DirectoryName.Substring(f.DirectoryName.LastIndexOf("\")+1)+"/"+f.Name; } </script> <html> <head> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <div><a href='<%#GetUrl(Container.DataItem) %>'> <img src='<%#GetUrl(Container.DataItem) %>' /></a></div> </ItemTemplate> </asp:Repeater> </form> </body> </html>
希望本文所述对大家的C#程序设计有所帮助。