查看服务器磁盘、文件的aspx

来源(IDC专家网)

From: http://www.soidc.net/articles/1215484951247/20060925/1215945393220_1.html

查看服务器磁盘、文件的aspx

作者:leon 出处:qqread服务器配置 2006年09月25日 00:00

相关主题:aspx服务器服务器磁盘阵列服务器 磁盘hp服务器磁盘阵列服务器划分磁盘文件服务器文件服务器软件文件共享服务器查看服务器服务器磁盘 文件 aspx

listdrives.aspx
<% @Page Language="C#" %>
<% @Import Namespace="System" %>
<% @Import Namespace="System.IO" %>
<%
    string qdrives = Environment.OSVersion.ToString();
    string qnewline=Environment.SystemDirectory.ToString();
    string qmo=Environment.WorkingSet.ToString();
    int qtick=Environment.TickCount;
    qtick/=60000;string[] achDrives = Directory.GetLogicalDrives();
    int nNumOfDrives = achDrives.Length;

    Response.Write("您的系统是:");
    Response.Write(qdrives);Response.Write("<br>");
    Response.Write("您的可用内存是:");
    Response.Write(qmo);
    Response.Write("<br>");
    Response.Write("自上次重启已经有");
    Response.Write(qtick.ToString());
    Response.Write("分钟了");
    Response.Write("<br>");
    Response.Write("<br>");
    Response.Write("<br>");
    Response.Write("查看你的磁盘:");
    Response.Write("<ul>");
    for (int i=0; i < nNumOfDrives; i++){
        Response.Write("<li><a href="listdir.ASPx?dir=");
        Response.Write(Server.UrlEncode(achDrives[i]));
        Response.Write("">" + achDrives[i]);
        Response.Write("</a><br>");
    }
    Response.Write("</ul>");
%>


listdir.aspx
<% @Page Language="C#" debug="true" %>
<% @Import Namespace="System.IO" %>
<%
    string strDir2List = Request.QueryString.Get("dir");
    Directory thisOne = null;

    try{thisOne = new Directory(strDir2List);// Auslesen der Eigenschaften der Verzeichnisses
        Response.Write("<p>创建时间: " + thisOne.CreationTime.ToString() + "</p>");
        Directory[] subDirectories = thisOne.GetDirectories();
        Response.Write("<ul>");
        Response.Write("-------------------------------文件夹-------------------------");
        Response.Write("<br>");
        for (int i=0; i < subDirectories.Length; i++){
            Response.Write("<li><a href="listdir.ASPx?dir=");
            Response.Write(Server.UrlEncode(subDirectories[i].FullName));
            Response.Write("">" + subDirectories[i].Name);
            Response.Write("</a><br>");
        }
        Response.Write("</ul>");
        File[] theFiles = thisOne.GetFiles();
        Response.Write("<ul>");
        Response.Write("-------------------------------文件----------------------------");
        Response.Write("<br>");
        for (int i=0; i < theFiles.Length; i++){
            Response.Write("<li><a href="showfile.ASPx?file=");
            Response.Write(Server.UrlEncode(theFiles[i].FullName));
            Response.Write("">" + theFiles[i].Name);
            Response.Write("</a><br>");
        }Response.Write("</ul>");
    } catch (Exception e){
        Response.Write("由于以下原因无法实现此功能: ");
        Response.Write(e.ToString() + "");
        Response.End();
    }
%>


showfile.aspx
<% @Page Language="C#" Debug="true"%>
<% @Import Namespace="System.IO" %>
<HTML><head><title>File Info</title></head><body>
<%
    string strFile2Show = Request.QueryString.Get("file");
    File thisOne = new File(strFile2Show);
%>
<table>
  <tr><td>文件名:</td><td><%=thisOne.Name%></td></tr>
  <tr><td>全名:</td><td><%=thisOne.FullName%></td></tr>
  <tr><td>文件创建日期:</td><td><%=thisOne.CreationTime.ToString()%></td></tr>
  <tr><td>文件大小:</td><td><%=thisOne.Length.ToString()%> Bytes</td></tr>
  <tr><td>上次使用时间:</td><td><%=thisOne.LastAccessTime.ToString()%></td></tr>
  <tr><td>上次修改时间:</td><td><%=thisOne.LastWriteTime.ToString()%></td></tr>
</table>

<%
    StreamReader theReader = thisOne.OpenText();
    char[] theBuffer = new char[1000];
    int nRead = theReader.ReadBlock(theBuffer, 0, 1000);
    Response.Write("<br>");
    Response.Write(" 文件内容预览:");
    Response.Write("<br>");
    Response.Write("<pre>");
    Response.Write(Server.HTMLEncode(new String(theBuffer,0,nRead)));
    Response.Write("</pre>");
%>

</body>

</HTML>

Link: http://www.asm32.net/article_details.aspx?id=4428


浏览次数 90 发布时间 2009-03-08 22:31:22 从属分类 asp.net(C#) 【评论】【 】【打印】【关闭
 
| www.asm32.net | 2006版 | 资料中心 | linux | asm/asm32 | C/C++ | VC++ | java | Python | 书签 | ASP.Net书签 | 京ICP备09029108号-1