C#顯示文件夾下所有圖片文件的方法
更新時間:2015年04月22日 12:08:17 作者:songguo
這篇文章主要介紹了C#顯示文件夾下所有圖片文件的方法,涉及C#操作圖片文件的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#顯示文件夾下所有圖片文件的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
<%@ 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#程序設(shè)計有所幫助。
相關(guān)文章
C#開發(fā)之int與string轉(zhuǎn)化操作
這篇文章主要介紹了C#開發(fā)之int與string轉(zhuǎn)化操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12
使用C#實現(xiàn)讀取系統(tǒng)配置文件的代碼實例講解
這篇文章主要介紹了使用C#實現(xiàn)讀取系統(tǒng)配置文件的代碼實例,使用到了ConfigurationManager類,需要的朋友可以參考下2015-12-12

