• 对文件夹进行操作浏览器中的文件列表


    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;

    public partial class _Default : System.Web.UI.Page 
    {
        
    protected void Page_Load(object sender, EventArgs e)
        {
            
    string strCurrentDir;
            strCurrentDir 
    = Server.MapPath(".");
            lblCurrentDir.Text 
    = strCurrentDir;

            FileInfo fi;
            DirectoryInfo di;
            TableCell td;
            TableRow tr;

            
    string FileName;
            
    string FileExt;
            
    long FileSize;
            DateTime FileModify;
            DirectoryInfo dir 
    = new DirectoryInfo(strCurrentDir);
            
    foreach (FileSystemInfo fsi in dir.GetFileSystemInfos())
            {
                FileName 
    = "";
                FileExt 
    = "";
                FileSize 
    = 0;
                
    if (fsi is FileInfo)
                {
                    fi 
    = (FileInfo)fsi;
                    FileName 
    = fi.Name;
                    FileExt 
    = fi.Extension;
                    FileSize 
    = fi.Length;
                    FileModify 
    = fi.LastWriteTime;
                }
                
    else
                {
                    di 
    = (DirectoryInfo)fsi;
                    FileName 
    = di.Name;
                    FileModify 
    = di.LastWriteTime;
                }
                tr 
    = new TableRow();
                td 
    = new TableCell();
                td.Controls.Add(
    new LiteralControl(FileName.ToString()));
                tr.Cells.Add(td);
                td 
    = new TableCell();
                td.Controls.Add(
    new LiteralControl(FileSize.ToString()));
                tr.Cells.Add(td);
                td 
    = new TableCell();
                td.Controls.Add(
    new LiteralControl(FileModify.ToString()));
                tr.Cells.Add(td);
                tbDirInfo.Rows.Add(tr);
            }
        }
    }

        <form id="form1" runat="server">
        
    <div>
            当前目录为:
    <asp:Label ID="lblCurrentDir" runat="server"></asp:Label><br />
            目录下文件的列表为:
    <br />
            
    <asp:Table ID="tbDirInfo" runat="server">
            
    </asp:Table>
        
    </div>
        
    </form>
  • 相关阅读:
    旋转骰子
    自我介绍
    【边带权 维护节点和根距离 两点距离】银河英雄传说
    【含义冲突判断】程序自动分析
    【01背包 合并费用】搭配购买
    【网格图环判断】格子游戏
    【连通块 维护size】 连通块中的点数
    【模板】 合并集合
    【出栈顺序判断】 Rails
    【整除分块】 余数之和
  • 原文地址:https://www.cnblogs.com/qixin622/p/753293.html
Copyright © 2020-2023  润新知