RT

解决方案 »

  1.   

    Directory.GetCurrentDirectory 获取应用程序的当前工作目录
    Directory.GetFiles 返回指定目录中的文件的名称
    File.GetAttributes 获取在此路径上的文件的 FileAttributes有很多这样的东西,在System.IO命名空间
      

  2.   

    还有 FileInfoMSDN:
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemIOFileInfoMembersTopic.htm
      

  3.   

    刚写的一个,看看和不合你的意思
    <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
    <%@ Import Namespace="System.IO"%>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title></title>
    </head>
    <script language="c#" runat="server">
      public void Page_Load(Object src,EventArgs e)
      {
        string strCurrentDir;
    //初始化一些数据
    if(!Page.IsPostBack)
    {
      strCurrentDir=Server.MapPath(".");
      lblCurrentDir.Text=strCurrentDir;
      tbCurrentDir.Text=strCurrentDir;
    }
    else
    {
      strCurrentDir=tbCurrentDir.Text;
      tbCurrentDir.Text=strCurrentDir;
      lblCurrentDir.Text=strCurrentDir;
    }

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

    //设定Table中的数据,先搞定第一行
    tr=new TableRow();

    td=new TableCell();
    td.Controls.Add(new LiteralControl("文件名"));
    tr.Cells.Add(td);

    td=new TableCell();
    td.Controls.Add(new LiteralControl("文件大小"));
    tr.Cells.Add(td);

    td=new TableCell();
    td.Controls.Add(new LiteralControl("更新时间"));
    tr.Cells.Add(td);

    tbDirInfo.Rows.Add(tr);

    string FileName;    //文件名称
    string FileExt;     //文件扩展名
    string FilePic;     //图像文件类型
    long FileSize;      //文件大小
    DateTime FileModify;   //最后更新时间

    DirectoryInfo dir=new DirectoryInfo(strCurrentDir);
    foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
    {
      FilePic="";
      FileName="";
      FileSize=0;
      FileExt="";
      
      if(fsi is FileInfo)
      {
        //表示当前fsi是文件
    fi=(FileInfo)fsi;
    FileName=fi.Name;
    FileExt=fi.Extension;
    FileSize=fi.Length;
    FileModify=fi.LastWriteTime;

    //通过扩展名来确定显示图片的类型
    switch(FileExt)
    {
      case ".jpg":
        FilePic="jpg图像";
        break;
      case ".gif":
        FilePic="gif图像";
    break;
      case ".tiff":
        FilePic="tiff图像";
    break;
      case ".bmp":
        FilePic="bmp图像";
    break;
      default:
        FilePic="文件";
    break;
    }
      }
      else
      {
        //当前为目录
    di=(DirectoryInfo)fsi;
    FileName=di.Name;
    FileModify=di.LastWriteTime;
    FilePic="目录";
      }
      //组建新的行
      tr=new TableRow();
      
      td=new TableCell();
      td.Controls.Add(new LiteralControl(FilePic+"&nbsp;"+FileName));
      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);
    }
      }
    </script>
    <body>
    <form runat="server">
    请选择浏览目录:<asp:TextBox ID="tbCurrentDir" runat="server" /><br>
    当前目录为:<asp:label ID="lblCurrentDir" runat="server" /><br>
    <asp:table ID="tbDirInfo" Font-Size="9pt" runat="server" /><br>
    </form>
    </body>
    </html>
      

  4.   

    在File类里有很多
    FileInfo也可以
      

  5.   

    很多也,遇事先问google,再问csdn,这种问题就不用问了
      

  6.   

    File 
    FileInfo
    就可以搞顶了.........