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


    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>
  • 相关阅读:
    du熊学斐波那契I
    《博客园精华集》分类索引
    C++中指针和引用的区别
    堆和栈的区别
    getch和getchar的区别
    class和struct
    ARM开发步骤
    ARM寻址方式
    存储器映射
    思维中的错误
  • 原文地址:https://www.cnblogs.com/qixin622/p/753293.html
Copyright © 2020-2023  润新知