返回顶部

收藏

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#

收藏

0人收藏

支持

0

反对

0

发表评论