ASP.NET檔案管理顯示資訊

來源:互聯網
上載者:User

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.IO;

namespace filemanage2

{

 /// <summary>

 /// login 的摘要說明。

 /// </summary>

 public class login : System.Web.UI.Page

 {

  protected System.Web.UI.WebControls.Label Label1;

  protected System.Web.UI.WebControls.Label Label3;

  protected System.Web.UI.WebControls.Label Label4;

  protected System.Web.UI.WebControls.Table Table1;

  protected System.Web.UI.WebControls.Button Button1;

  protected System.Web.UI.WebControls.Label Label2;

  protected System.Web.UI.WebControls.Label Label6;

  protected System.Web.UI.WebControls.Label Label5;

  protected System.Web.UI.WebControls.Label Label7;

  protected System.Web.UI.HtmlControls.HtmlInputFile myFile;

 

  private void Page_Load(object sender, System.EventArgs e)

  {

   // 在此處放置使用者代碼以初始化頁面

   if(!this.IsPostBack)

   {

////    if(Session["smallfools_filemanage"]!=null)

////    {

//     if(Session["smallfools_filemanage"].ToString()!="pass")

//     {

//      Response.Redirect("index.aspx");

//     }

//     else

//     {

      ListFile();

//     }

//    }

//    else

//    {

//     Response.Redirect("index.aspx");

//    }

   }

  }

  private void ListFile()

  {

   //接收路徑

   string strPath=Request.QueryString["path"];

   //系統標識符和版本號碼

   string strSystem = Environment.OSVersion.ToString();

   //擷取映射到進程內容相關的實體記憶體量

   string strRem=Environment.WorkingSet.ToString();

   //擷取系統啟動後經過的毫秒數

   int iTC=Environment.TickCount/60000;

   //系統目錄的完全限定路徑

   string strSD=Environment.SystemDirectory;

   //擷取此本機電腦的 NetBIOS 名稱

   string strMN=Environment.MachineName;

   //擷取與目前使用者關聯的網路網域名稱

   string strUDN=Environment.UserDomainName;

   this.Label5.Text="系統:"+strSystem;

   this.Label6.Text="可用記憶體:"+strRem;

   this.Label7.Text="自上次重啟已有:"+iTC+"分鐘了";

   this.Label7.Text=this.Label7.Text+"<br>系統路徑:<a href='login.aspx?path="+strSD+"'>"+strSD+"</a>";

   this.Label7.Text=this.Label7.Text+"<br>電腦的名稱:"+strMN;

   this.Label7.Text=this.Label7.Text+"<br>網路網域名稱:"+strUDN;

   //如果接收的路徑為空白,則擷取當前路徑

   if(strPath==null)

   {

    strPath=Request.ServerVariables["APPL_PHYSICAL_PATH"];

   }

   else

   {

    if(strPath.Substring(strPath.Length-1,1)!="\\")

    {

     strPath=strPath+"\\";

    }

   }

   this.Label1.Text="當目錄:"+strPath;

   try

   {

    //輸出所有磁碟機代號

    string[] drv=System.IO.Directory.GetLogicalDrives();

    this.Label3.Text="磁碟機:";

    for(int i=0;i<drv.Length-1;i++)

    {

     this.Label3.Text=this.Label3.Text+"<a href='login.aspx?path="+drv[i]+"'>"+drv[i]+"</a> ";

    }

    //目前的目錄下的所有檔案夾

    DirectoryInfo di=new DirectoryInfo(strPath);

    DirectoryInfo[] wjj=di.GetDirectories();

   

    //上級目錄

    if(strPath.Substring(strPath.Length-2,2)!=":\\")

    {

     string[] aa=strPath.Split('\\');

     string bb="";

     for(int i=0;i<aa.Length-2;i++)

     {

      if(i==0)

      {

       bb=aa[i];

      }

      else

      {

       bb=bb+"\\"+aa[i];

      }

     }

     this.Label4.Text="<br><a href='login.aspx?path="+bb+"'>上級目錄:..</a> ";

    }


    //輸出目前的目錄下的所有檔案夾

    foreach(DirectoryInfo diTemp in wjj)

    {

     TableRow tr=new TableRow();

     //tr.BackColor=ColorTranslator.FromHtml("#dddddd");

     tr.Attributes.Add("class","folder");

     tr.Attributes.Add("onmouseover","this.className='2'");

     tr.Attributes.Add("onmouseout","this.className='folder'");

     

     TableCell td=new TableCell();

     //檔案夾名

     td=new TableCell();

     td.Text="<a href='login.aspx?path="+strPath+diTemp.Name+"'>"+diTemp.Name+"</a>";

     tr.Cells.Add(td);

     //空列

     td=new TableCell();

     tr.Cells.Add(td);

     //屬性

     td=new TableCell();

     td.Text=diTemp.Attributes.ToString().Replace("Archive","存檔").Replace("Compressed","壓縮").Replace("Device","保留").Replace("Directory","目錄").Replace("Encrypted","加密").Replace("Hidden","隱藏").Replace("Normal","正常").Replace("NotContentIndexed","非索引").Replace("Offline","離線").Replace("ReadOnly","唯讀").Replace("ReparsePoint","重新分析點").Replace("SparseFile","稀疏").Replace("System","系統").Replace("Temporary","臨時");

     tr.Cells.Add(td);

     //建立時間

     td=new TableCell();

     td.Text=diTemp.CreationTime.ToString();

     tr.Cells.Add(td);

     //最後訪問時間

     td=new TableCell();

     td.Text=diTemp.LastAccessTime.ToString();

     tr.Cells.Add(td);

     //最後修改時間

     td=new TableCell();

     td.Text=diTemp.LastWriteTime.ToString();

     tr.Cells.Add(td);

     //刪除

     string strBack=strPath+diTemp.Name;

     strBack=strBack.Replace("\\","\\\\");

     td=new TableCell();

     td.Text="<a href=# onclick=\"javascript:delfolder('"+strBack+"')\">刪除</a>";

     td.HorizontalAlign=HorizontalAlign.Center;

     tr.Cells.Add(td);

     //移動或重新命名

     td=new TableCell();

     td.Text="<a href=# onclick=\"javascript:movefolder('"+strBack+"')\">移動/重新命名</a>";

     td.HorizontalAlign=HorizontalAlign.Center;

                    tr.Cells.Add(td);

     this.Table1.Rows.Add(tr);

    }

    //目前的目錄下的所有檔案

    FileInfo[] fi=di.GetFiles();

    foreach(FileInfo fiTemp in fi)

    {

     

     TableRow tr=new TableRow();

     //tr.BackColor=ColorTranslator.FromHtml("#eeeeee");

     tr.Attributes.Add("class","file");

     tr.Attributes.Add("onmouseover","this.className='2'");

     tr.Attributes.Add("onmouseout","this.className='file'");

     TableCell td=new TableCell();

     //檔案名稱

     td=new TableCell();

     td.Text="<a href='read.aspx?path="+strPath+fiTemp.Name+"'target=_blank><font color=#000000>"+fiTemp.Name+"</font></a>";

     tr.Cells.Add(td);

     //大小

     td=new TableCell();

     td.Text=fiTemp.Length.ToString();

     td.HorizontalAlign=HorizontalAlign.Right;

     tr.Cells.Add(td);

     //屬性

     td=new TableCell();

     td.Text=fiTemp.Attributes.ToString().Replace("Archive","存檔").Replace("Compressed","壓縮").Replace("Device","保留").Replace("Directory","目錄").Replace("Encrypted","加密").Replace("Hidden","隱藏").Replace("Normal","正常").Replace("NotContentIndexed","非索引").Replace("Offline","離線").Replace("ReadOnly","唯讀").Replace("ReparsePoint","重新分析點").Replace("SparseFile","稀疏").Replace("System","系統").Replace("Temporary","臨時");

     tr.Cells.Add(td);

     //建立時間

     td=new TableCell();

     td.Text=fiTemp.CreationTime.ToString();

     tr.Cells.Add(td);

     //最後訪問時間

     td=new TableCell();

     td.Text=fiTemp.LastAccessTime.ToString();

     tr.Cells.Add(td);

     //最後修改時間

     td=new TableCell();

     td.Text=fiTemp.LastWriteTime.ToString();

     tr.Cells.Add(td);

     //刪除

     string strBack=strPath+fiTemp.Name;

     strBack=strBack.Replace("\\","\\\\");

     td=new TableCell();

     td.Text="<a href=# onclick=\"javascript:delfile('"+strBack+"')\">刪除</a>";

     td.HorizontalAlign=HorizontalAlign.Center;

     tr.Cells.Add(td);

     //移動或重新命名

     td=new TableCell();

     td.Text="<a href=# onclick=\"javascript:movefile('"+strBack+"')\">移動/重新命名</a>";

     td.HorizontalAlign=HorizontalAlign.Center;

     tr.Cells.Add(td);

     this.Table1.Rows.Add(tr);

    }

   }

   catch(Exception ex)

   {

    this.Button1.Visible=false;

    this.myFile.Visible=false;

    this.Label2.Text="<br><p align=center>"+ex.Message+"</p>";

   }

  }

  #region Web Form Designer generated code

  override protected void OnInit(EventArgs e)

  {

   //

   // CODEGEN:該調用是 ASP.NET Web Form設計器所必需的。

   //

   InitializeComponent();

   base.OnInit(e);

  }

  

  /// <summary>

  /// 設計器支援所需的方法 - 不要使用代碼編輯器修改

  /// 此方法的內容。

  /// </summary>

  private void InitializeComponent()

  {   

   this.Button1.Click += new System.EventHandler(this.Button1_Click);

   this.Load += new System.EventHandler(this.Page_Load);

  }

  #endregion

  private void Button1_Click(object sender, System.EventArgs e)

  {

   if(this.myFile.PostedFile!=null)

   {

    //接收路徑

    string strPath=Request.QueryString["path"];

    //如果接收的路徑為空白,則擷取當前路徑

    if(strPath==null)

    {

     strPath=Request.ServerVariables["APPL_PHYSICAL_PATH"];

    }

    else

    {

     if(strPath.Substring(strPath.Length-1,1)!="\\")

     {

      strPath=strPath+"\\";

     }

    }

    //處理字串

    string strName=this.myFile.PostedFile.FileName;

    int i=strName.LastIndexOf("\\");

    string strNewName=strName.Substring(i);

    string strFullName=strPath+strNewName;

    //儲存檔案

    this.myFile.PostedFile.SaveAs(strFullName);

    //Response.Redirect("index.aspx?path="+strPath);

    this.Label2.Text="<center><font color=red>上傳成功</font></center>";

    ListFile();

   }

  }

 }

}

--------------------------------------------------------------------------------------------------------------------------------------

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.