asp.net遍历指定物理路径文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="../css/css.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #ul_photo li { width: 13em; height: 13em; margin: 1.5em; border: solid 1px #ccc; float: left; overflow: hidden; text-align: center; }
        #ul_photo li img { width: 110px; height: 103px; border: 0px; margin-top: 10px; }
        #txtDirName { font-size: 12px; color: #dedede; width: 200px; }
        .sspan { cursor: pointer; margin-top: 1em; }
        #btnSelect { display: none; }
        .margtbtdb td { line-height: 24px; font-size: 14px; }
        a:link, a:visited { color: #666666; }
        a:hover { color: Red; }
    </style>
</head>
<body>
    <form runat="server">
    <table class="marg_tb" cellpadding="0" cellspacing="0" style="border-top: 0px">
        <tr>
            <td class="margtbtdc">
                <img src="../images/martb.png" />静态文件资源库
            </td>
        </tr>
        <tr>
            <td class="margtbtdb">
                <table id="filetb" style="text-align: center">
                    <tr>
                        <th>
                            <a href="javascript:void(0)" onclick="ckSelectAll('filetb')" />全选</a>
                        </th>
                        <th style="width: 360px; text-align: left;">
                            <asp:LinkButton ID="lkFileName"  runat="server" oncommand="lkFileName_Command">文件名</asp:LinkButton>
                        </th>
                        <th style="width: 100px">
                            <asp:LinkButton ID="LinkButton2" runat="server">类型</asp:LinkButton>
                        </th>
                        <th style="width: 60px">
                            <asp:LinkButton ID="LinkButton3" runat="server">大小</asp:LinkButton>
                        </th>
                        <th style="width: 186px">
                            <asp:LinkButton ID="LinkButton4" runat="server">文件创建时间</asp:LinkButton>
                        </th>
                        <%--<th style="width: 186px">
                文件修改时间
            </th>--%>
                    </tr>
                    <asp:Repeater ID="rptPhoto" runat="server">
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <input runat="server" id="ckItem" value='<%#Eval("FilePath") %>' type="checkbox" />
                                </td>
                                <td style="width: 360px; text-align: left;">
                                    <a target="_blank" title="点击查看" href='<%# Eval("FileName","../../{0}") %>'>
                                        <%# Eval("FileName") %></a>
                                </td>
                                <td>
                                    静态页面
                                </td>
                                <td>
                                    <%# Eval("FileSize").ToString()+"kb" %>
                                </td>
                                <td>
                                    <%# Eval("CreateDate").ToString()%>
                                </td>
                                <%--<td>
                        <%# Eval("UpdateDate").ToString()%>
                    </td>--%>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </table>
            </td>
        </tr>
        <tr>
            <td style="padding-top: 2em">
                <asp:Button OnClientClick="return isSelectAll(this.value)" ID="btnDelete" runat="server"
                    CssClass="minbtn" CommandArgument="false" Text="删除" OnClick="btnDelete_Click" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

C#代码:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Model;
using System.Text.RegularExpressions;
using System.Web.UI.HtmlControls;

public partial class manager_ResourceLibrary_HtmlSources : System.Web.UI.Page
{
    private static List<Model.FileAttribute> fileList = new List<FileAttribute>(10);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string path = Request.PhysicalApplicationPath;
            //if (Request.QueryString["path"] != null && Request.QueryString["path"] != "")
            //{
            //    path = path + @"/" + Server.UrlDecode(Request.QueryString["path"]);
            //}
            if (Directory.Exists(path))
            {
                string[] strs = Directory.GetFiles(path);//获得路径下的所有文件名


                for (int i = 0; i < strs.Length; i++)
                {
                    Model.FileAttribute fileAttribute = new FileAttribute();

                    FileInfo fi = new FileInfo(strs[i]);
                    fileAttribute.FileSize = Convert.ToInt32(fi.Length);
                    //fileAttribute.UpdateDate = fi.;
                    fileAttribute.CreateDate = fi.CreationTime;
                    fileAttribute.FileName = fi.Name;
                    fileAttribute.FilePath = fi.FullName;
                    if (new Regex(@".+\.html").IsMatch(fileAttribute.FileName) && File.Exists(fi.FullName))
                    {
                        fileList.Add(fileAttribute);
                    }
                }
                //fileList.Sort();
                this.rptPhoto.DataSource = fileList;
                this.rptPhoto.DataBind();

            }
        }
    }
}
效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值